Remove/Replace/Delete Carriage Returns/Line Returns/paragraph returns

Problem: Imported document has many extra carriage returns (or line returns or paragraph returns) at the end of Object Text.

There are many threads in this forum about this subject and I am very confused. I would love to have a dxl that can be put in the User drop down in the module tool bar that a user can click on to strip out any extra carriage returns at the end of an object or selected objects.

I tried using the built in "Find" function using regular expression but it does not recognize "\n" or "\r" or "\t" or "\v" or "\f". In Word you can use ^p to find and replace extra paragraph returns and I thought maybe the find and replace function DOORS could do the same but I was not successful.

The samples of code included in the existing threads in this forum provide good input for someone who knows how to program. I am not in that category.

Does anyone have a tested script that can replace/remove these extra returns?
SystemAdmin - Wed Apr 03 09:25:22 EDT 2013

Re: Remove/Replace/Delete Carriage Returns/Line Returns/paragraph returns
SystemAdmin - Wed Apr 03 10:05:15 EDT 2013

Hello RobK,
I made something like this a while ago. My guess that what you imported in was rich text and not plain text. Rich text has the carriage returns as \par instead of \n. I'll attach some code that might work. It first filters for objects with multiple carriage returns and then strips the last carriage return off. You might have to run it several times to strip all the carriage returns off. The searchDouble/fixDouble is used for plain text, the searchExtra and fixExtra is for rich text. Currently the plain text fix is commented out.

Greg
Attachments

attachment_14972955_FixExtraNewLines.dxl

Re: Remove/Replace/Delete Carriage Returns/Line Returns/paragraph returns
SystemAdmin - Wed Apr 03 10:24:53 EDT 2013

Hi

Returns you can remove
 

Regexp regSplit = regexp2("^([^\n]*)\n(.*)$");
 
string sTest = "123\n456";
 
if(regSplit(sTest)) {
    print "0: " sTest[match 0] "\n";
        print "1: " sTest[match 1] "\n";
        print "2: " sTest[match 2] "\n";
}

 


yiedls to the output

 

 

 

0: 123
456
1: 123
2: 456



But you have to find out the yourself if it is extra or not.

Best regards
Wolfgang



 

 

Re: Remove/Replace/Delete Carriage Returns/Line Returns/paragraph returns
llandale - Wed Apr 03 11:19:34 EDT 2013

Its rather tricky to strip out raw text '\n' '\r' whatever while preserving RichText and OLE.

In your case you want to do that work in Word before you import it; typically:
  • replace ^p^p
  • with ^p
and keep replacing until you get zero replaces. then replace ^l^p with ^p.

-Louie

Re: Remove/Replace/Delete Carriage Returns/Line Returns/paragraph returns
SystemAdmin - Wed Apr 03 13:05:56 EDT 2013

Thank you - the script was just what I needed. I reactivated the lines in the main program and it worked like a charm.
I will still tell folks to be more careful when cutting and pasting new text.

Re: Remove/Replace/Delete Carriage Returns/Line Returns/paragraph returns
Mike.P.Adams - Thu Jun 23 14:05:11 EDT 2016

Hello,

What I am tring to do is to output from DOORS the text with the RTF settings preserved.  Issue is that when I use the commands to copy to the clipboard an extra line feed is added.  What I need to do is to remove this line feed before pasting from the clipboard.  I have stumbled across this topic before, but it was not of interest to me at that time.  Try as I can now, I cannot find the posting.  If possible, would you please send me the link to the post answering this question?

Thanks in advance.