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: Replacing text in DXL
Topic Summary:
Created On: 26-May-2004 19:39
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 Stuart Gilbey, on Thursday, May 27, 2004 3:35 PM

Answer:
Try using regular expressions and the match function. The following should give you the index in the string of the first occurrence:

Regexp encodeStr = regexp "~newline~"
string t = "First Line of Text~newline~Second Line of Text"
if ( encodeStr t) {
t[match 1]
int index = start 0
}


You could place this in a while loop to replace all occurrences such as: (I haven't tested this!)

Regexp encodeStr = regexp "~newline~"
string t = "First Line of Text~newline~Second Line of Text"
while ( encodeStr t) {
t[match 1]
int startIndex = start 0
int endIndex = end 0
t = t[0:startIndex-1] "\n" t[endIndex+1:length(t)-1]
}

Hope this helps.
 26-May-2004 19:39
User is offline View Users Profile Print this message


Adam Terrenzio

Posts: 14
Joined: 24-Nov-2003

I need to write Object Text to a file on a single line. In that text I need to 'encode' the newline character '\n' in order to be able to write it on a single line in the file.
Also I need to be able to read the same file and interpret encodings of the newline character.

I have no problem encoding the newline character into some sequence of characters (ie. '\n' = "~newline~"), but I have trouble decoding.
I am using the "int contains(Buffer b, string word, int offset)" function which says that it will return the index at which the string word appears in the buffer provided that it is preceded by a non-alphanumeric character.
Well, isalnum('~') returns false and still the function contains doesn't catch the occurence of string "~newline~".
Ex:
string t = "First Line of Text~newline~Second Line of Text"
Buffer b = create
b=t
int i = contains(b,"~newline~", 0)
print i

This will return -1 indicating it didn't find the occurence of "~newline~" in the text.

Is there maybe some other way of doing this?

Thanks!
Report this to a Moderator Report this to a Moderator
 27-May-2004 08:27
User is offline View Users Profile Print this message


Stuart Gilbey

Posts: 4
Joined: 14-May-2003

Answer Answer
Try using regular expressions and the match function. The following should give you the index in the string of the first occurrence:

Regexp encodeStr = regexp "~newline~"
string t = "First Line of Text~newline~Second Line of Text"
if ( encodeStr t) {
t[match 1]
int index = start 0
}


You could place this in a while loop to replace all occurrences such as: (I haven't tested this!)

Regexp encodeStr = regexp "~newline~"
string t = "First Line of Text~newline~Second Line of Text"
while ( encodeStr t) {
t[match 1]
int startIndex = start 0
int endIndex = end 0
t = t[0:startIndex-1] "\n" t[endIndex+1:length(t)-1]
}

Hope this helps.


-------------------------
Stuart Gilbey
C4 Systems Limited
www.c4systems.co.uk
Report this to a Moderator Report this to a Moderator
 27-May-2004 10:08
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

Hi Stuart,

I would use Regular Expressions too,
but match, start and end are independant.

That means
match x will return the range which matched (a:b),
start x will return the begin of matched part (a),
end x will return the end of matched part (b).
So you can say match x = (start x:end x)

The number (x) indicates which matched part you mean :
0 is the hold part
1-9 are parts within your regular, which are in brackets

So the line t[match 1] is senseless, because you don't use the return value and you don't have a part 1 in your regular.
You can simply leave it out ;-))

Grettings
Reik Schroeder
Siemens AG Berlin



-------------------------
Evosoft GmbH
for Siemens Industry Sector


Berlin, Germany
Report this to a Moderator Report this to a Moderator
 27-May-2004 16:07
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

On a side note: your loop appears to me to KEEP looking from the beginning of the string once you've done a replacement. That's not a problem since the TO phrase "\n" is NOT a substring of the FROM phrase "~newline~". But if FROM was "a" and to was "aa" you'd end up in an infinate loop. That could be resolved by searching recursively restricting the next search to the REST of the buffer.

- Louie
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 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 1 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.