-2

I'm trying to make 2 variables of one. This is the variable: "12345678900&mtc".

I need variables "12345678900" and "mtc".

user4157124
  • 2,809
  • 13
  • 27
  • 42
  • 1
    You probably want to look at [StringSplit()](https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm) – garbb Dec 12 '17 at 15:05

2 Answers2

1

… 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"

Related.

user4157124
  • 2,809
  • 13
  • 27
  • 42
0

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)
iamtheky
  • 134
  • 1
  • 1
  • 3