Page 1 of 1

Auto-formatting tool for removing double spaces

Posted: Wed Feb 03, 2010 4:44 pm
by prr
I often paste content from the web into a word processor, and would like to be able to eliminate double- and even triple-spacing between paragraphs in one fell swoop. Is there any such autoformatting command that I can use that would accomplish this? I didn't see anything in the OO user guide. I looked in the autocorrect options, and only saw in the Options tab, the option to remove blank paragraphs. Is this what I want to do? Or is there another option I can use? Or would I need a macro of some kind?

Re: Auto-formatting tool for removing double spaces

Posted: Wed Feb 03, 2010 5:27 pm
by RoryOF
Find and Replace will do the job. Press the Replace all button

Re: Auto-formatting tool for removing double spaces

Posted: Wed Feb 03, 2010 11:39 pm
by acknak
I often use something like this:

Edit > Find & Replace
Search for: [:space:]+
Replace with: space
Options: Regular expressions: YES

Click "Replace all"

That will replace one or more consecutive space characters of any kind (including things like non-breaking spaces) with exactly one plain space.

Stuff that's pasted from the 'Net has all kinds of oddball junk--beside the extra spaces--in it. It could be pretty handy to have a nice way to handle it.

Re: Auto-formatting tool for removing double spaces

Posted: Thu Feb 04, 2010 9:21 am
by Robert Tucker
prr wrote:I often paste content from the web into a word processor, and would like to be able to eliminate double- and even triple-spacing between paragraphs in one fell swoop.
Do you mean it's creating extra paragraphs breaks, inserting blank paragraphs? You can eliminate these easily by installing AltSearch and searching for \p\p\p and replacing with \p\p. You might also want to look at this macro:

http://www.oooforum.org/forum/viewtopic.phtml?t=6429

Re: Auto-formatting tool for removing double spaces

Posted: Fri Apr 30, 2010 12:00 am
by prr
Installed AltSearch but looking for \p\p didn't turn anything up. Not sure what the problem is. One click in MS Word does autoformatting which takes care of all of this for me. Hopefully I'll stumble across something here...

Re: Auto-formatting tool for removing double spaces

Posted: Wed May 05, 2010 7:11 pm
by prr
acknak wrote:I often use something like this:

Edit > Find & Replace
Search for: [:space:]+
Replace with: space
Options: Regular expressions: YES

Click "Replace all"

That will replace one or more consecutive space characters of any kind (including things like non-breaking spaces) with exactly one plain space.

Stuff that's pasted from the 'Net has all kinds of oddball junk--beside the extra spaces--in it. It could be pretty handy to have a nice way to handle it.
Can you explain exactly what you type in? What I typed in didn't come up with any hits. What do you type in with the search for, and replace with? The colon and plus sign confused me...

Re: Auto-formatting tool for removing double spaces

Posted: Wed May 05, 2010 8:02 pm
by acknak
You should type in the "Search for:" box exactly the bold text in my post:
  • [:space:]+
In fact, you can copy/paste the blue text above into the box.

Type one space character in the "Replace with:" box.

Make sure that the "Regular expressions" option is on; you have to click on the "More Options" button to see it.

Re: Auto-formatting tool for removing double spaces

Posted: Thu May 06, 2010 6:09 am
by JohnV
would like to be able to eliminate double- and even triple-spacing between paragraphs in one fell swoop.
I just wrote a macro to do this a week ago for another person with the same request.

Code: Select all

Sub StripEmptyParagraphs
b = CInt(InputBox("Entry maximum empty paragraphs ( 0 is a valid entry ).",,1))
oDoc = ThisComponent
FandR = oDoc.createReplaceDescriptor
FandR.SearchRegularExpression = true
FandR.setSearchString("\n")
FandR.setReplaceString("\n")
oDoc.ReplaceAll(FandR) 'Change line breaks to paragraph breaks
oTC = oDoc.Text.createTextCursor
While oTC.isEndOfParagraph 'Remove blank paragraphs from top of doc.
  oTC.goRight(1,true)
  oTC.String = ""
Wend 
Do While oTC.goToNextParagraph(False)
 p = p + 1
Loop
oTC = oDoc.Text.createTextCursor
Do While oTC.gotoNextParagraph(false)
 pc = pc + 1
 If oTC.isEndOfParagraph then c = c + 1
 If c > b then
  Do While oTC.isEndOfParagraph
  oTC.goRight(1,true)
  oTC.String = ""
  lc = lc + 1
  If lc > p then exit do
  Loop
  lc = 0 
  c = 0
 EndIf
 If pc > p then exit do
Loop
End Sub

Re: Auto-formatting tool for removing double spaces

Posted: Fri May 07, 2010 9:03 pm
by prr
The macro works on some of these spaces between paragraphs, but not all. See, for example, this document. It will remove only a few of the large gaps.

EDIT: Acknak, thanks for clarifying your actions, but the same thing--on the attached doc, the vast majority (if not all) the spaces are not removed.

Re: Auto-formatting tool for removing double spaces

Posted: Fri May 07, 2010 9:29 pm
by JohnV
When I open Versailles.rtf with OOo it is using a paragraph style with spacing both above and below the paragraph. Do Ctrl+A and apply the Default paragraph style and this spacing will go away.

Re: Auto-formatting tool for removing double spaces

Posted: Fri May 07, 2010 9:39 pm
by RoryOF
In Text Body style spacing above and below the paragraph is set to 0.42cm (say 12 pts). You should check the Help file on Styles and how to modify them.

Re: Auto-formatting tool for removing double spaces

Posted: Fri May 07, 2010 11:17 pm
by prr
RoryOF wrote:In Text Body style spacing above and below the paragraph is set to 0.42cm (say 12 pts). You should check the Help file on Styles and how to modify them.
The spaces I'm talking about are a lot greater than 2/5 of a cm.

Re: Auto-formatting tool for removing double spaces

Posted: Fri May 07, 2010 11:21 pm
by prr
JohnV wrote:When I open Versailles.rtf with OOo it is using a paragraph style with spacing both above and below the paragraph. Do Ctrl+A and apply the Default paragraph style and this spacing will go away.
OK that is one quick solution when this happens---select all, then apply a paragraph style that has no (or just limited) spacing before and after paragraphs. That actually wouldn't even require a macro....

Re: Auto-formatting tool for removing double spaces

Posted: Fri May 07, 2010 11:39 pm
by RoryOF
prr wrote:
RoryOF wrote:In Text Body style spacing above and below the paragraph is set to 0.42cm (say 12 pts). You should check the Help file on Styles and how to modify them.
The spaces I'm talking about are a lot greater than 2/5 of a cm.
They are most probably 0.42 cm after the para above and 0.42cm before the para below. Modify your Text Body Style to remove these two settings and see where that gets you.
 Edit: Also, turn ON Display Formatting characters and look at your file again. There are several extra paragraph marks which need to be removed. 

Re: Auto-formatting tool for removing double spaces

Posted: Tue Jun 08, 2010 6:15 am
by Murph
I am having the opposite problem - I have text with a mixture of single and double spacing and I would like to make sure it is all double spaced. I tried replacing ". " with ". " but this adds the extra space to an existing double space. Is there a code for a non-space character? e.g. say * = represents any letter or number I could replace ". *" with ". *"

Thanks

Murph

Re: Auto-formatting tool for removing double spaces

Posted: Tue Jun 08, 2010 11:13 am
by Robert Tucker
Murph wrote:I am having the opposite problem - I have text with a mixture of single and double spacing and I would like to make sure it is all double spaced. I tried replacing ". " with ". " but this adds the extra space to an existing double space. Is there a code for a non-space character? e.g. say * = represents any letter or number I could replace ". *" with ". *"
Search: ([^:space:]) ([^:space:])
Replace: $1 $2
(Regular expressions checked, of course)

for some reason has a problem with "I"s.

You could replace all spaces by two spaces then repeatedly replace three spaces by two spaces until no more three spaces are found.

Re: Auto-formatting tool for removing double spaces

Posted: Tue Jun 08, 2010 3:07 pm
by acknak
Search: ([^:space:]) ([^:space:])
I don't think does what you expect it to do :shock:

I think it should work if you just use plain spaces in the pattern: ([^_])_([^_]) (where the "_" represents a plain space character).

Re: Auto-formatting tool for removing double spaces

Posted: Tue Jun 08, 2010 3:59 pm
by Robert Tucker
acknak wrote:
Search: ([^:space:]) ([^:space:])
I don't think does what you expect it to do
No. I thought it would find any character except a space separated by a space from any character except a space. It does but not when an "I" is involved. I'd be interested in the explanation for that.
acknak wrote:I think it should work if you just use plain spaces in the pattern: ([^_])_([^_]) (where the "_" represents a plain space character).
Yes, I'd tried with (^ ) (^ ) but didn't have any success, of course.

Re: Auto-formatting tool for removing double spaces

Posted: Sat Jun 12, 2010 4:03 pm
by acknak
It does but not when an "I" is involved. I'd be interested in the explanation for that.
Robert Tucker wrote:
acknak wrote:
Search: ([^:space:]) ([^:space:])
I don't think does what you expect it to do
No. I thought it would find any character except a space separated by a space from any character except a space. It does but not when an "I" is involved. I'd be interested in the explanation for that.
Anything other than "[:space:]" is not recognized as the named class. So [^:space:] is a plain, ordinary character class: it matches any character except the letters s, p, a, c, e or colon.

At least I think that's what happens--does that square with your "I" example?

Re: Auto-formatting tool for removing double spaces

Posted: Sat Jun 12, 2010 5:43 pm
by Robert Tucker
acknak wrote:...does that square with your "I" example?
Looking at it again it seems more than the "I"s are affected. I get this result for Search for: ([^:space:]) ([^:space:]) Replace with: $1 $2.

Before:
space_replace-01.png
space_replace-01.png (6.68 KiB) Viewed 36880 times
After:
space_replace-02.png
space_replace-02.png (6.84 KiB) Viewed 36880 times
From your explanation I can understand that it doesn't change to a double-space between "opposite" and "problem". But why no double-space between "I" and "am" and "the" and "opposite" and so on?

Re: Auto-formatting tool for removing double spaces

Posted: Sat Jun 12, 2010 7:45 pm
by Bill
There's another problem when single non-space characters are both preceded by a space and followed by a space. During a first run of Search and Replace, the combination of a character-space-"I" is found and replaced. The search then continues with the space following "I", so the combination of "I"-space-character isn't found during the first run. Search and Replace has to be run a second time to find the "I"-space-character combinations.

Re: Auto-formatting tool for removing double spaces

Posted: Sat Jun 12, 2010 11:20 pm
by acknak
... why no double-space between "I" and "am" and "the" and "opposite" and so on?
The entire pattern has to match--if either one of the characters around the space matches the excluded class, the whole pattern fails to match. So "I a" doesn't match because "a" is a member of the excluded set; "e o" because "e" is excluded.

The problem posed is tough to do with a regular expression for English prose because English has complicated rules for punctuation. It often requires some analysis of the context to determine for sure where the end of a sentence is--at least for the general case.

Re: Auto-formatting tool for removing double spaces

Posted: Sun Aug 19, 2012 3:10 pm
by bro.norman
Acknak's remedy resolve the same issue in LibreOffice 3.5. I was searching for the the tag in LibreOffice and after applying all of it, nothing worked. I know OpenOffice uses the same source code as LibreOffice so I googled the tag, this time instead of LibreOffice, I used OpenOffice. I tried Acknak''s remedy which was slightly different than that in LibreOffice' community. It worked. Thanks acknak.

Re: Auto-formatting tool for removing double spaces

Posted: Tue Feb 19, 2019 11:27 am
by nikkitytom
[quote="acknak" quote] Thanks so much. I’ve spend days looking for this solution. Typing [:space:]+ into the Find All box works like a charm. But ‘typing one space character’ into the Replace All box needs clarification. There’s no “character” for one space, instead you have to just press the space bar once ... be careful that the cursor is in position before you press that space bar. Only ONCE. What is confusing is that the space bar doesn’t show anything in the Replace All box. The cursor has merely advanced one space.
This works like a charm, but I’ve pulled out half my hair searching for it. :bravo:

Re: Auto-formatting tool for removing double spaces

Posted: Tue Feb 19, 2019 1:05 pm
by Bill
A space is a character. It's the first "printable" character on the list of ASCII characters.

ASCII

ascii codes

Re: Auto-formatting tool for removing double spaces

Posted: Tue Feb 19, 2019 1:23 pm
by nikkitytom
Sorry, I stand corrected ... I was confused by the blank space. I followed your link ASCII and it is as complex String Theory. There are so many queries regarding this simple operation that I'm guessing I'm not alone in my befuddlement. "Hit the Space Bar once" would have solved the problem.