东西活学活用才好! 比如你给出的示例中, 可以先清除掉多余的空格再处理吧?
这里我先举个笨拙但易理解的:
#include<Array.au3>
$str = "a b"
While 1
If StringInStr($str, ' ') Then
$str = StringReplace($str,' ', ' ')
Else
ExitLoop
EndIf
WEnd
$s = StringSplit($str," ")
_ArrayDisplay($s)
$ss = ""
For $i = 1 To $s[0]
$ss = $ss & StringLen($s[$i]) & @CRLF
Next
MsgBox(0,"",$ss)
最后想说, 如果经常性的又想方便的处理各类字符串, 那很有必要学一学正则表达式.
比如上面的相关示例可以这样处理, 更简洁和方便:
#include<Array.au3>
$str = "a b"
$s = StringRegExp($str, '\H', 3)
_ArrayDisplay($s)
$str = StringRegExpReplace($str, '\h+', ' ')
MsgBox(0, 'Deleted', $str)
|