When using ASP to process text. The string length detection function that comes with the system is sometimes not very useful. For example, a Chinese character will only count as one byte. If it is all Chinese characters during typesetting, it is easy to say that there is no difference anyway. However, if the string to be manipulated contains both Chinese characters and English letters, it will be inconvenient. The following three functions can Replaces the related functions that come with ASP.
There is also something to note. If used in a loop, the invariant i is also a variable commonly used in loops. When the following function is executed, the value of i will change. If the same variable is used in the loop that calls it, unknown values will occur. If the result is found, please use another variable name.
The following usage is the same as len(), left(), right().
program code
Copy the code code as follows:
FunctionStrlength(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 For
Next
End Function
FunctionStrright(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 For
Next
End Function