VBScript Failed to filter characters without ascii

I have this function:

Private Sub CheckParams(Values) Dim Str, Ch If IsArray(Values) then Str = Join(Values, "") Else Str = Values End If For I = 1 To Len(Str) Ch = Asc(Mid(Str, I, 1)) If Not ((Ch = 9) Or (Ch = 10) Or (Ch = 13) Or ((Ch > 31) And (Ch < 128))) Then SetError("script result contains illegal characters.") End If Next End Sub 


This function throws an error if the input value has characters that are not in the list, according to the If statement in the For loop. The problem is that when my input value has Japanese characters, validation is passed without errors. I think the Asc () function, which is used to return the character's ANSI code, does not know how to handle Japanese characters.
What is apparently the problem?
Does Asc () function return negative numbers?

+4
source share
2 answers

I have found a solution. This is very similar to Ansgar's solution, but instead of MidB, I used Mid with 1:
ch = AscW(Mid(str, i, 1))

+1
source

Kanji and Kana are most likely represented as double-byte Unicode characters, so you can try something like this:

 ch = AscW(MidB(str, i, 2)) 
+1
source

Source: https://habr.com/ru/post/1484806/


All Articles