WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mueer01 on January 26, 2016, 05:58:14 AM

Title: string replace question
Post by: mueer01 on January 26, 2016, 05:58:14 AM
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




Title: Re: string replace question
Post by: td on January 26, 2016, 06:36:23 AM
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%%")
Title: Re: string replace question
Post by: mueer01 on January 26, 2016, 06:50:45 AM
YEPP! That works!
Many thanks, 99 pts for you.

- close -