Unexpected behavior from _StringExplode ()

I have a string: string1 string2 - string3 string4 . I need it to break into two parts on - (pay attention to the space on either side of the "-"). I have the following code that does not work 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 this to be string3 string4 .

enter image description here

There should be a little supervision, but it's hard for me to find it.

+3
source share
1 answer

& hellip; explain what I'm doing wrong & hellip;

AutoIt v3.3.12.0 error (fixed in the serial beta). Alternatively, you can use StringSplit() :

 #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 the $STR_NOCOUNT parameter in StringSplit() returns an array identical to _StringExplode() .

+3
source

Source: https://habr.com/ru/post/907620/


All Articles