Page 1 of 1

[Solved-Workaround] Replace paragraph break with line break

Posted: Thu Feb 13, 2014 8:02 pm
by John_Ha
I would like to replace all paragraph breaks (enter) with line breaks (shift/enter). Is there an expression for line break in the Replace box?

It is easy to replace line breaks with paragraph breaks with Search = \n (finds line break) and Replace = \n (replaces with paragraph break).

I have searched extensively but can only find things saying it cannot be done ...

All help will be appreciated.

Re: Replace paragraph break with line break (soft return)

Posted: Thu Feb 13, 2014 8:17 pm
by RoryOF
This is a very bad idea in OpenOffice (if it is even possible). OpenOffice does not like (read: really hates) paragraphs longer than 64K characters; Line breaks do not read as paragraph breaks, and one can end up with documents that will take no further input.

Re: Replace paragraph break with line break (soft return)

Posted: Thu Feb 13, 2014 8:27 pm
by John_Ha
Rory
Thanks. I agree wholeheartedly! ...

... but I have a special purpose here which applies only to the text I have in one table, so it doesn't spread to the whole document.

I regularly get sent a fairly complex table where the non-WP-literate person uses about 50 paragraph returns instead of line breaks. I just want to change them to line breaks instead of doing them manually.

I know I could Format > Paragraph and set gap to zero, but that interferes with something else. I really do want line breaks!

Re: Replace paragraph break with line break (soft return)

Posted: Thu Feb 13, 2014 8:48 pm
by acknak
John_Ha wrote:I would like to replace all paragraph breaks (enter) with line breaks (shift/enter). Is there an expression for line break in the Replace box? ...
No--that's the only problem.

OO running on Linux will accept a literal "line feed" character in the "replace with" field, but not on WIndows or Mac.

Hmm ... a simple workaround just occurred to me and it seems to work just fine:

Enter a line break normally and copy it to the clipboard

Edit > Find & Replace
Search for: $
Options/Regular expressions: ON
Click "Find All"

Edit > Paste

Re: Replace paragraph break with line break (soft return)

Posted: Thu Feb 13, 2014 10:53 pm
by JohnV
Very slick, acknak! A new solution to a very old problem.

Re: Replace paragraph break with line break (soft return)

Posted: Fri Feb 14, 2014 4:34 am
by MrProgrammer
acknak wrote:OO running on Linux will accept a literal "line feed" character in the "replace with" field, but not on WIndows or Mac.
Macs can easily insert a line feed in the Replace With box using the Mac's Show Character Viewer feature. It works with any application.
Screen shot 2014-02-13 at 20.25.21 .png

Re: Replace paragraph break with line break (soft return)

Posted: Fri Feb 14, 2014 4:39 am
by acknak
Oops :oops: Trying to write from memory again. Thanks!

It may work on Windows too, now. It's been a long time (WinXP) since I checked.

Re: Replace paragraph break with line break (soft return)

Posted: Fri Feb 14, 2014 9:40 pm
by John_Ha
acknak wrote:Hmm ... a simple workaround just occurred to me and it seems to work just fine:
acknak
Thanks - that is very neat. All I need to get that to work in a macro is a way to load the clipboard with the copied line break ...

I have tried all possible ways using Find and replace, but the Replace box always refuses to recognise the copied soft line break, and does not accept \x000A or \#09, so it pastes a nul, which effectively deletes the paragraph return. I have the Alt Find & Replace add-on which does exactly what I want using \n as the Replace term so I looked inside the add-on and I think the actual expression it uses (line 3553) is as below (I hope your Czech is better than mine!):

Code: Select all

    case "t" ' vložit tabulator
       prCurs.string = chr(9)  ' vlozit text
       prCurs.collapseToEnd
       
    case "n" ' vložit line break 
       prCurs.text.insertControlCharacter(prCurs, com.sun.star.text.ControlCharacter.LINE_BREAK, false )
       prCurs.collapseToEnd

    case "S" ' vlozit pevnou mezeru 
       prCurs.text.insertControlCharacter(prCurs, com.sun.star.text.ControlCharacter.HARD_SPACE, false )
       prCurs.collapseToEnd
where I think the first case replaces with a tab, the second case with a Line break and the third case with a Hard space. But I am not sure how to put the com.sun.star.text.ControlCharacter.LINE_BREAK into a macro.

I tried to record a macro when I used Alt Find & Replace. It did the changes I want, but the Stop Recording window disappeared and I couldn't save what I had recorded.

I think I will have to use your method (or Alt Find & Replace) manually after the macro has run doing everything else.