Unexpected behavior from _StringExplode()

久未见 提交于 2019-12-23 20:16:59

问题


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.

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


回答1:


… 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().



来源:https://stackoverflow.com/questions/30324676/unexpected-behavior-from-stringexplode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!