For example, a Chinese character can only be regarded as one byte. If it is all Chinese Characters During the typographical process, there is no difference. However, if the operated string contains Chinese characters and English letters, this is inconvenient. The following three functions can replace the relevant functions provided by ASP.
Note that, when used in a loop, the variable "I" is also commonly used in the loop. When the following function is executed, the value of "I" changes, if the same variable is used in the call cycle, unknown results will be generated. Please use another variable name.
The following uses the same as Len (), left (), right.
ProgramCode Copy codeThe Code is as follows: function strlength (STR)
Temp_str = Len (STR)
For I = 1 to temp_str
Test_str = (mid (STR, I, 1 ))
If ASC (test_str)> 0 then
Strlength = strlength + 1
Else
Strlength = strlength + 2
End if
Next
End Function
Function strleft (STR, L)
Temp_str = Len (STR)
For I = 1 to temp_str
Test_str = (mid (STR, I, 1 ))
Strleft = strleft & test_str
If ASC (test_str)> 0 then
Lens = Lens + 1
Else
Lens = Lens + 2
End if
If lens> = l then exit
Next
End Function
Function strright (STR, L)
Temp_str = Len (STR)
For I = temp_str to 1 step-1
Test_str = (mid (STR, I, 1 ))
Strright = test_str & strright
If ASC (test_str)> 0 then
Lens = Lens + 1
Else
Lens = Lens + 2
End if
If lens> = l then exit
Next
End Function