I'm trying to make 2 variables of one. This is the variable: "12345678900&mtc
".
I need variables "12345678900
" and "mtc
".
I'm trying to make 2 variables of one. This is the variable: "12345678900&mtc
".
I need variables "12345678900
" and "mtc
".
… make 2 variables of one.
As per Documentation - Function Reference - StringSplit()
:
Splits up a string into substrings depending on the given delimiters.
Example:
Global Const $g_sString = '12345678900&mtc'
Global Const $g_sDelimiter = '&'
Global Const $g_aArray = StringSplit($g_sString, $g_sDelimiter)
Global Const $g_sMsgTpl = '$g_aArray[1] = "%s"\n$g_aArray[2] = "%s"\n'
Global Const $g_sMsgRes = StringFormat($g_sMsgTpl, $g_aArray[1], $g_aArray[2])
ConsoleWrite($g_sMsgRes)
Returns:
$g_aArray[1] = "12345678900"
$g_aArray[2] = "mtc"
also stringmid will get you there
local $str = "12345678900&mtc" , $var1 = StringMid($str , 1 , StringInStr($str , "&") - 1), $var2 = StringMid($str , StringInStr($str , "&") + 1)
consolewrite($str & @CR & $var1 & @CR & $var2 & @CR)
also formatting the string into assigns via regular expression and executing it
execute(stringregexpreplace("12345678900&mtc" , '(.+?)&(.*)' , 'Assign("var1" , "$1") Assign("var2" , "$2")'))
ConsoleWrite(eval("var1") & @CR & eval("var2") & @CR)