Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiline string, replace all and at specific specific line
#1
I have a big multi line string which contains line-break characters "[ ]" (carriage return+linefeed)

And I want to do 2 type of replacements
1) Cycle through every "line" and replace every "line" that begins with "x" or "y" with "1234"
xbbb and yccc are replaced with 1234

2) Target a specific "line number", => line 3 "yccc" and replace it with "1234"

Macro Macro28
Code:
Copy      Help
str s="aaa[]xbbb[]yccc[]ddd[]eee[]ffff" ;;etc...etc... (big string)

; replacement 1 output: s="aaa[]1234[]1234[]ddd[]eee[]ffff"
; replacement 2 output: s="aaa[]xbbb[]1234[]ddd[]eee[]ffff"

I have done this easily by putting the string in an array. But is it possible to do the replacements I described above by manipulating string "s" only.

With "putting the string in an array" I mean like this:
arr[0]=aaa
arr[1]=xbbb
etc...

I do not know if I am using the correct terminology when using the terms like "line" and "line number", because the string does not contain line-numbers or lines. From the help-file "A string is an array of characters.". But I still used these terms to describe the problem and the desired output.
#2
Macro Macro2071
Code:
Copy      Help
out

str s="aaa[]xbbb[]yccc[]ddd[]eee[]ffff" ;;etc...etc... (big string)

s.replacerx("^[xy][^[]]*" "5678" 8)
out s

_i=_s.getl(s 2); if(_i>=0) s.replace("1234" _i _s.len)
out s
#3
That's it!

Thank you!!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)