Unexpected behavior from _StringExplode()
Asked Answered
H

1

3

I have a string: string1 string2 - string3 string4. I need it split in two at the - (note the space on either side of the "-"). I have the following code which isn't working as expected:

#include <MsgBoxConstants.au3>
#include <String.au3>

Local $test = _StringExplode("string1 string2 - string3 string4", " - ")

MsgBox($MB_SYSTEMMODAL, "Title", $test[1])

The output is string2. I expected it to be string3 string4.

enter image description here

Must be a small oversight but I'm having trouble finding it.

Horologist answered 19/5, 2015 at 11:43 Comment(0)
P
3

… explain what I'm doing wrong …

It's a bug concerning AutoIt v3.3.12.0 (solved in successive beta). Alternatively StringSplit() can be used:

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>

Global Const $g_aTest = StringSplit('string1 string2 - string3 string4', ' - ', $STR_ENTIRESPLIT)

MsgBox($MB_SYSTEMMODAL, 'Title', $g_aTest[2])
_ArrayDisplay($g_aTest)

Including $STR_NOCOUNT to StringSplit()'s flag parameter returns array identical to _StringExplode().

Pinnatipartite answered 19/5, 2015 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.