In ASP. The actual length containing the Chinese string is detected in NET

xiaoxiao2021-03-06  18

The following is in ASP. The NET detected the actual length containing the Chinese string, which may be used in many places.

VB. NET's Write: Function Strlength (Byval Str As String) AS Integer Dim EN As ASCIENCODING = New Asciiencoding () Dim B AS Byte () = en.getbytes (STR) DIM I as Integer = 0 DIM Length AS Integer = 0 for i = 0 to B.LENGTH-1 IF B (i) = 63 Then Length = 1 End if Length = 1 Next Return Length End Function

The following is a C # method: Function Int Strlength (String Str) {asciiencoding en = new asciiencoding (); Byte [] b = en.getbytes (str); int length = 0; for (i = 0; i <= b .Length-1; i ) {if (b == 63) {length = 1;} backth = 1;} return longth;}

However, this code will be slower.

转载请注明原文地址:https://www.9cbs.com/read-44508.html

New Post(0)