VBScript error 0x800a0005 working with strings

This is what I need to code, but the runtime error

[code]dim StrInput, StrOutput, StrArray, i, TmpStr

StrInput = "这是一个utf-8字符串! .txt"
StrArray = Split(StrInput,";")

For i = LBound(StrArray) to UBound(StrArray)
If InStr(StrArray(i), "&#") = 1 Then
StrOutput = StrOutput + ChrW(Right(StrArray(i),Len(StrArray(i))-2))
Else
StrOutput = Left(StrArray(i), InStr(StrArray(i),"&#") - 1)
End If
Next
[/code]

Modified into this is ok,But that's not what I want results

[code]dim StrInput, StrOutput, StrArray, i, TmpStr

StrInput = "这是一个utf-8字符串! .txt"
StrArray = Split(StrInput,";")

For i = LBound(StrArray) to UBound(StrArray)
If InStr(StrArray(i), "&#") = 1 Then
StrOutput = StrOutput + ChrW(Right(StrArray(i),Len(StrArray(i))-2))
Else
StrOutput = Left(StrArray(i), InStr(StrArray(i),"&#"))
End If
Next[/code]

You're not handling the case where the string doesn't contain "&#", which means InStr is returning 0 (and you're then calling Left with -1 as the parameter).

Try something like the following:

[code]Dim StrInput, StrOutput, StrArray, i, TmpStr

StrInput = "这是一个utf-8字符串! .txt"
StrArray = Split(StrInput,";")

For i = LBound(StrArray) To UBound(StrArray)
If InStr(StrArray(i), "&#") = 1 Then
StrOutput = StrOutput + ChrW(Right(StrArray(i),Len(StrArray(i))-2))
ElseIf InStr(StrArray(i), "&#") > 1 Then
StrOutput = Left(StrArray(i), InStr(StrArray(i),"&#") - 1)
Else
StrOutput = StrOutput + strArray(i)
End If
Next[/code]

I want to

utf-8&#23383

Processing into

utf-8

and

&#23383The corresponding unicode characters

[quote="jon"]You're not handling the case where the string doesn't contain "&#", which means InStr is returning 0 (and you're then calling Left with -1 as the parameter).

Try something like the following:

[code]Dim StrInput, StrOutput, StrArray, i, TmpStr

StrInput = "这是一个utf-8字符串! .txt"
StrArray = Split(StrInput,";")

For i = LBound(StrArray) To UBound(StrArray)
If InStr(StrArray(i), "&#") = 1 Then
StrOutput = StrOutput + ChrW(Right(StrArray(i),Len(StrArray(i))-2))
ElseIf InStr(StrArray(i), "&#") > 1 Then
StrOutput = Left(StrArray(i), InStr(StrArray(i),"&#") - 1)
Else
StrOutput = StrOutput + strArray(i)
End If
Next[/code][/quote]

thx this ok