Purpose
Replace substrings in a given variable

Solution 1: Use an intermediate text variable and the ReplaceText command
GuiXT
//sample value
Set V[list] "a,b,c"    
                        
Set text[temp] "&V[list]" 
ReplaceText "temp" from="," to=";" 
Set V[list] "&text[temp]" 

Message "&V[list]"




You can specify the new string in hexadecimal notation, e.g. to insert line breaks:
GuiXT
//sample value
Set V[list] "a,b,c"    
                        
Set text[temp] "&V[list]" 
ReplaceText "temp" from="," toHexCode="0d0a" 
Set V[list] "&text[temp]" 

Message "&V[list]"




Instead of individual characters, you can use any character string to search and replace:
GuiXT
//sample values
Set V[eqlocation] "{street}, {city}" 
Set V[eqcity] "Rome" 
Set V[eqstreet] "220 Largo Benedetto Marcello" 

Set text[temp] "&V[eqlocation]" 
ReplaceText "temp" from="{city}" to="&V[eqcity]" 
ReplaceText "temp" from="{street}" to="&V[eqstreet]" 
Set V[eqlocation] "&text[temp]" 
                        
Message "&V[eqlocation]" 





Solution 2:
Use regular expressions

The Set command has the special options regex= and regexReplace=, which allow flexible manipulation of character strings, although there are a few pitfalls to be aware of.

GuiXT
//sample value
Set V[list] "a,b,c"    
                        
Set V[listtemp] "&V[list]" regex="," regexReplace=";"
if Q[ok]
  Set V[list] "&V[listtemp]" 
endif

Message "&V[list]"




Pitfall 1: GuiXT returns an empty string if the regex expression does not match. For this reason, the command
  Set V[list] "&V[list]" regex="," regexReplace=";"
returns an empty string if V[list] does not contain a comma; for example, the string "a" becomes "". You need an intermediate variable and the "if Q[ok]".


Regular expressions allow you to search for more than one string at the same time:
GuiXT
//sample value
Set V[list] "a,b;c,d"    

Set V[listtemp] "&V[list]" regex=",|;" regexReplace=" "
if Q[ok]
  Set V[list] "&V[listtemp]" 
endif

Message "&V[list]"




Pitfall 2: Regular expressions define a series of characters with a special meaning. You must place a backslash in front of these characters so that they are handled as normal characters, otherwise the result may be surprising:

GuiXT
 //sample value
Set V[list] "a|b|c|d"    

Set V[listtemp] "&V[list]" regex="|" regexReplace=","
if Q[ok]
  Set V[list] "&V[listtemp]" 
endif

Message "&V[list]"
  
                


Special characters in regular expressions:





With a backslash before | the result is as expected:

GuiXT
 //sample value
Set V[list] "a|b|c|d"    

Set V[listtemp] "&V[list]" regex="\|" regexReplace=","
if Q[ok]
  Set V[list] "&V[listtemp]" 
endif

Message "&V[list]"
  


Components: InputAssistant