Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Regular expressions to remove end of line CRs
Topic Summary:
Created On: 22-Feb-2005 18:15
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by , on Friday, March 11, 2005 4:49 PM

Answer:
Ken,

Perhaps the text you are dealing with is in Rich Text Format rather than plain text. If so, removing newlines from the RTF markup won't do much, since they are treated as whitespace and are ignored anyway. RTF newlines are usually denoted with the \par control word.

If you are dealing with RTF markup, you might want to give the attached script a try. I've found it does a pretty good job of removing trailing newlines in "Object Text".

The provide code sample processes the "Object Text" attribute of each displayed object in the current module and populates a "Trimmed Text" attribute with the newline-trimmed text. You will need to create an object attribute of type "Text" named "Trimmed Text" before running this script in a module. Once you are confident the script is doing the right thing, you could modify it to replace "Object Text" with the newline-trimmed version of the text.

Note that manipulating RTF markup directly like this is a dangerous thing. However this is the only way I have found so far of trimming trailing newlines from rich text attributes.
 22-Feb-2005 18:15
User is offline View Users Profile Print this message


Ken Mcguffie

Posts: 63
Joined: 3-Feb-2004

Hi,

I am struggling with regular expressions. I have objects containing text with carriage returns at the end. I want to do a global find and replace to remove them. I have tried (\n)$ but it is finding occurences of text ending with n.

Any one know what I am doing wrong?

Thanks

Ken McGuffie
Report this to a Moderator Report this to a Moderator
 22-Feb-2005 18:39
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

Here is example of script that will print 3 different lines

// regular expression DXL example
/*
  examples of regular expression DXL
*/
Regexp line = regexp ".*"
// matches any character except newline
string txt1 = "line 1\nline 2\nline 3\n" 
// 3 line string
while (!null txt1 && line txt1) {
    print txt1[match 0] "\n" 
    // match 0 is whole of match
    txt1 = txt1[end 0 + 2:]   // move past newline
}
Report this to a Moderator Report this to a Moderator
 23-Feb-2005 01:36
User is offline View Users Profile Print this message


Shawn Stepper

Posts: 96
Joined: 6-Aug-2004

I have tried this several ways in the "Replace" dialog, and have had no success. I tried \n, \\n, \\\n and none of them were recognized as a line feed. It always did a literal match. I think the only way to do what you want is to write some DXL code.

-------------------------
Shawn Stepper
shawn.e.stepper@wellsfargo.com
Report this to a Moderator Report this to a Moderator
 23-Feb-2005 13:27
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

To help you out more the following rewrite of the code replace carriage return with a semicolon in current object text.

Object o = current

Regexp line = regexp ".*" // matches any character except newline
string txt1 = o."Object Text"
string s = ""

while (!null txt1 && line txt1) {
     s=s txt1[match 0] ";" //replace carriage return with semicolon
     txt1 = txt1[end 0 + 2:] // move past newline
}
o."Object Text" = s

Report this to a Moderator Report this to a Moderator
 23-Feb-2005 14:13
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

To do the same thing without regular expressions

Object o = current

string clean(string sTemp)

{ string sReturn=""

char cChar

for(iPosition=0;iPosition <length sTemp;iPosition++)

{ cChar=sTemp[iPosition]

if( cChar!='\n' )

{ sReturn=sReturn cChar ""

} else sReturn = sReturn ";"

} //end for

return sReturn

} //end string

string s = o."Object Text"

s = clean(s)

o."Object Text"=s

Report this to a Moderator Report this to a Moderator
 9-May-2006 21:34
User is offline View Users Profile Print this message


jason haury

Posts: 10
Joined: 13-Oct-2005

I've attached a script that will remove all whitespace from the beginning and end of a piece or RichTextFormat (RTF) Object Text.  If there are any newlines ("/n"),  tabs ("/t"), or spaces (" ") that precede or trail any non-whitespace characters or OLEs, those pieces of white space are removed.


I tried to implement this with RichText and RichTextParagraph objects, but couldn't get it to work.  Also, The code could be a bit shorter if I implemented it with Regular Expressions. 


Just a note to anyone dealing RTF code: all of the apparent "new lines" in the RTF code itself are actually "carriage returns" so you have to look for "\r" rather than "\n"


Report this to a Moderator Report this to a Moderator
 10-May-2006 17:49
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

I didn't follow Jason's code. But if I were writing a DXL to strip leading and trailing white space from a RichText attribute (Object Text), I'd take advantage of the fact that "cutRichText" perm takes positions relative to the RAW text. So get the raw and the richTextWithOld, find the white space in the Raw text, then use those positions to cut it out of the Rich text.

- Louie
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 0 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 0 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.