用正则,一行代码搞定~#include <Array.au3>
Local $Max = 220 ;--------只需指定最大长度
Local $Str = _
'SIC25-2-TP08 50 PCS 總部-檢驗倉-存貨送檢到貨' & @CRLF & _
'SIC53-1-TC11 50 PCS 總部-檢驗倉-存貨送檢到貨' & @CRLF & _
'SCK3950-C 50 PCS 總部-檢驗倉-存貨送檢到貨' & @CRLF & _
'SCK4965-C 34 PCS 總部-檢驗倉-存貨送檢到貨' & @CRLF & _
'SCK4965-C 33 PCS 到貨 總部-檢驗倉-存貨送檢' & @CRLF & _
'ER16-1/8mm-A 109 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER20-6mm-A 353 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER20-7mm 1000 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER16-1.5mm 29 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER16-2.5mm 200 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER16-4.5mm 142 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER16-5.5mm 53 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER16-6.5mm 100 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'ER16-8.5mm 100 PCS 到貨 總部-成品倉-1OO ' & @CRLF & _
'EOC32B-10 2 PCS 到貨 總部-成品倉-1OO '
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExp($str, '(?s)(?<=\n|^)(.{1,' & $Max & '}|.*)(?=\r|$)', 3)
If @Error Then Exit(MsgBox(48, @Error, '无法分段')
_ArrayDisplay($Test, UBound($Test))
;-----------以下可查看具体结果
Local $i, $Out = ''
For $i = 0 To UBound($Test) - 1
$Out &= $Test[$i] & @CRLF & '=============================' & @CRLF
Next
Msgbox(64, '分 ' & UBound($Test) & ' 段结果', $Out)
|