![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Replacing text in DXL Topic Summary: Created On: 26-May-2004 19:39 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() 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. | |
![]() |
|
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! |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Replacing text in DXL
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.