Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

A WiseScript find and replace in a variable

Created: 06 Nov 2013 • Updated: 13 Nov 2013 | 3 comments
This issue has been solved. See solution.

Hi there,

Without going into too much detail, is it possible using wise script to do a simple find and replace in a variable?

So for example, I have a variable called VAR1 = C:\FolderName

And then I want it to become VAR1 = C$\FolderName

So in effect, all I need to do here is replace the colon with a dollar symbol.

I've been playing around with the PARSE commands, reading txt files back into variables after updating them and I just can't fathom it out, if someone (Edt!) wouldn't mind helping me then it would much appreciated, thank you.

Paul

Operating Systems:

Comments 3 CommentsJump to latest comment

EdT's picture

Parse VAR1 into variables LEFT and RIGHT using the colon as the delimiter at the point where it should split the string. The colon is not carried over.

NEWVAR1 = %LEFT%"$"%RIGHT%  where NEWVAR1 is the new string, LEFT contains C and RIGHT contains \FolderName. The $ is included as a simple text string.

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.

SOLUTION
Paul1977's picture

Sometimes things are just too simple, thanks again for your help there, appreciated as always.
Worked perfectly with a little tweaking, below is just a reference (incase I ever need again, or anyone else for that matter)

item: Set Variable
  Variable=LEFT
  Value=BASSOL-PKGL-01
end
item: Set Variable
  Variable=INSTALLDIR_CLIENT
  Value=c:\New Folder
end
item: Remark
end
item: Remark
end
item: Parse String
  Source=%INSTALLDIR_CLIENT%
  Pattern=:
  Variable1=LEFT1
  Variable2=RIGHT
end
item: Set Variable
  Variable=INSTALLDIR_NET
  Value=%LEFT1%$%RIGHT%
end
item: Remark
end
item: Display Message
  Title=TEST
  Text=%INSTALLDIR_NET%
  Text=
  Text=\\%LEFT%\%INSTALLDIR_NET%
  Text=
  Text=Should have no backslashes on the end of either line.
end
 

EdT's picture

I think your use of LEFT and LEFT1 is going to cause you confusion later on. Why not use SERVER instead of LEFT as this is more descriptive and relevant to what you are setting this variable to.

I personally reserve the variables LEFT and RIGHT for parsing operations only - that way I alway know what to expect in these variables.

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.