editing strings
-
- Posts: 233
- Joined: Sun Aug 24, 2014 5:26 pm
editing strings
I have NAMEs like "0123ABCD_1", "4567EFAB_2", etc. How can i write last 2 simbols ("_1", "_2" and so on) to another variable, then remove it from NAME to finally get two separate parts. For example if i have NAME = "4567EFAB_5" it should transform to NAME = "4567EFAB" and INDEX = "_5"
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: editing strings
There are various solutions, in your specific case I would adopt the following:
Please note that the 's' operator of the String command works only with numbers so you cannot use %s
Code: Select all
set NAME string "4567EFAB_2"
string NAME s "%x_%d" VAR1 VAR2
print "%VAR1%"
print "%VAR2%"
Please note that the 's' operator of the String command works only with numbers so you cannot use %s
-
- Posts: 233
- Joined: Sun Aug 24, 2014 5:26 pm
Re: editing strings
Thanks, and what is the solution if name looks like this "V81BobbyPreDisease07_7", simple names (not hex numbers) at the beginning and index at the end?
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: editing strings
Code: Select all
set NAME string "4567EFAB_2"
set VAR1 string NAME
set VAR2 string NAME
string VAR1 > "_"
string VAR2 ! "_"
print "%VAR1%"
print "%VAR2%"