StringReplace issue

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
cvlr
Newbie
Posts: 18
Joined: Thu Jun 07, 2018 4:40 pm

StringReplace issue

Post by cvlr » Thu Sep 13, 2018 3:35 pm

The instructions state that if result variable is omitted then the original variable will be modified. It will not however if you are replacing something with a space AND do not use the variable again, unless you use the space constant.
Let>test=this is cat
StringReplace>test,is, ,
does not work.
Replacing is with a space works fine if you specify test afterwards but not if you omit it.
StringReplace>test,is, ,test
Or if you do this StringReplace>test,is,space

Something else:
let>cat=that
stringreplace>cat,a,nullchar,result

Returns th not tht
You have to simply use stringreplace>cat,a,,result

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: StringReplace issue

Post by Marcus Tettmar » Fri Sep 14, 2018 7:27 am

Works for me:

Let>string=abcd
StringReplace>string,b,

There's a space at the end of the line above.

In any case it's hard to read as you can't see spaces very well. So I would do:

StringReplace>variable,something,{" "}

Or

StringReplace>variable,something,SPACE

But it IS working for me with just a space character.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: StringReplace issue

Post by JRL » Fri Sep 14, 2018 7:33 pm

The issue for cvlr is the third (last) comma. Leave the last comma out and StringReplace> will work without the last result variable parameter. Add that last comma and the function wants you to specify the fourth (result variable) parameter.

As for the nullchar issue. The problem is that the macro editor will not see any characters past the nullchar location. Nullchar (ASCII character 0) will block the remaining characters from being viewed. If you write the variable out to a file then view the file contents using notepad you will find that variable "result" has become
"th t" and will work anyplace where ASCII character 0 is usable.

Code: Select all

let>cat=that
stringreplace>cat,a,nullchar,result
writeln>%temp_dir%nulltest.txt,wres,result
ExecuteFile>%temp_dir%nulltest.txt

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts