Search code examples
splitautoit

Making 2 variables of 1


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

I need variables "12345678900" and "mtc".


Solution

  • … 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.