我有以下格式的字符串:
示例1:ABC,0,ABCD,ABC,ABC,ABC,ABC,ABC,11,ABC,ABC,toRemove,012,234
示例2:ABC,0,ABCD,ABC,ABC,ABC,ABC,ABC,11,ABC,ABC,toRemove,012,234
如果字符串包含以逗号分隔的14个值(而不是13个值),则删除12.值
上面的第二行包含一个空格,如果存在,也应该删除。
答案 0 :(得分:1)
StringSplit
已有一个计数器(元素0),因此无需使用Ubound
)。
像StringSplit
将字符串转换为数组一样,ArrayToString
会将数组转换回字符串。
#include <array.au3>
$tmp_line = "ABC,0,ABCD,ABC,ABC,ABC,ABC,ABC,11,ABC,ABC, ToRemove,012,234"
$line = StringSplit($tmp_line, ",")
If $line[0] = 14 Then
$new_line = ArrayToString($line, ",", 1, 11) & "," & ArrayToString($line, ",", 13)
Else
$new_line = $line ; shouldn't this be $new_line = $tmp_line ?
EndIf
MsgBox(0, $line[0], $tmp_line & @CRLF & $new_line)
答案 1 :(得分:-1)
解决了:
$ line = StringSplit($ tmp_line,“,”)
$ count_values = Ubound($ line)
If $count_values = 14 Then
$new_line = $line[1] & "," & $line[2] & "," & $line[3] & "," & $line[4] & "," & $line[5] & "," & $line[6] & "," & $line[7] & "," & $line[8] & "," & $line[9] & "," & $line[10] & "," & $line[12] & "," & $line[13]
Else
$new_line = $line
EndIf