_StringExplode()的异常行为 [英] Unexpected behavior from _StringExplode()
问题描述
我有一个字符串:string1 string2 - string3 string4
.我需要将它在-
处一分为二(注意-"两侧的空格).我有以下代码无法正常工作:
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])
输出为string2
.我希望它是string3 string4
.
必须是一个小小的疏忽,但是我很难找到它.
Must be a small oversight but I'm having trouble finding it.
推荐答案
…解释我在做什么错了…
… explain what I'm doing wrong …
它是 StringSplit()
:
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)
在StringSplit()
的flag参数中包含$STR_NOCOUNT
会返回与_StringExplode()
相同的数组.
Including $STR_NOCOUNT
to StringSplit()
's flag parameter returns array identical to _StringExplode()
.
这篇关于_StringExplode()的异常行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!