2015年1月26日 星期一

VB.NET 字數限制



        Dim str_temp As String = String.Empty, maxlength As Integer = 50, a1 As Integer = 0, a2 As Integer = 0
        Dim n As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding()
        Dim b() As Byte = Nothing
        b = n.GetBytes(TextBox2.Text)
        For i As Integer = 0 To b.Length - 1
            If b(i) = 63 Then
                a1 = a1 + 1
            Else
                a2 = a2 + 1
            End If
        Next

        Response.Write("byte長度:" & b.Length & ";全形(包含中文字、標點符號)=" & a1 & ";半形(英文字、標點符號)=" & a2)


以上有錯誤請指正,謝謝

沒有留言:

張貼留言