string replace question

Started by mueer01, January 26, 2016, 05:58:14 AM

Previous topic - Next topic

mueer01

Hello,

I want to replace the string
xxx"100%"xxx
by
xxx"25%"xxx

I tried

if buf == "xxx"100%"xxx"             THEN buf = "xxx"25%"xxx"   
if buf == ""xxx"100%%"xxx""       THEN buf = ""xxx"25%%"xxx""   
if buf == """xxx"100%%"xxx"""    THEN buf = """xxx"25%%"xxx"""   
if buf == """"xxx"100%%"xxx"""" THEN buf = """"xxx"25%%"xxx""""   

all is wrong! Any idea?

Regards,
Erhard





td

You are close but
Code (winbatch) Select
buf = "xxx""100%%""xxx"
if buf == "xxx""100%%""xxx"       THEN buf = "xxx""25%%""xxx" 

is likely what you want.  You can also do something like this:
Code (winbatch) Select
buf = 'xxx"100%%"xxx'
if buf == 'xxx"100%%"xxx'       THEN buf = 'xxx"25%%"xxx' 

which many may find more readable.

You can also use the StrReplace function, if you can make a few assumptions about your strings:
Code (winbatch) Select
buf = 'xxx"100%%"xxx'
buf=StrReplace(buf,"100%%", "25%%")
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mueer01

YEPP! That works!
Many thanks, 99 pts for you.

- close -