![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: function Find and Replace any string Topic Summary: Created On: 8-Aug-2007 12:49 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
Hi,
though i could not find this kind of function, i wrote it myself.
This function is a familiar strreplace function.
Thanks to Stuart for the key-idea.
regards
thomas
|
|
![]() |
|
![]() |
|
I guess everybody writes this routine from time to time ... :-)
Just one note: it was posted here from time to time, that regular expressions are quite memory and time consuming. If you use your routine in a massive loop, this could be an issue. I'd therefore propose to create one routine taking the regexp as argument, and a second, overloaded routine with your original arguments. Thus you have both options, and if you find yourself using the same search and replace in a long loop, you could take the version with regexp as argument. The attached script runs less than 1 second when the regexp is created once, and 6 seconds when the regexp is created in each step. Plus the latter one consumes more memory. Regards, Peter |
|
![]() |
|
![]() |
|
Yes, regexp is pretty slow. The famous example would be the function that determines if the raw text contains 'shall'; you are much better off declaring Regexp HasShall = regexp([S|s][H|h]..] outside that function, rather than inside.
I think you should be more conserned with the massive memory leak associated with the way you break apart and put the string back together. You should put the string into a buffer and use buffer combine functions to rebuild the string. Using a loop instead of recursion should likewise save time and space. Also be advised that both examples given work only on raw text. Rich Text replaces are a lot trickier. - Louie |
|
![]() |
|
![]() |
|
Hi all,
thanks for your useful advice.
@Louie - if i'm forced to do this with rich text, ill contact you
![]() |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
function Find and Replace any string
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.