1 2 3 4 5 6 7 8 | Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim test As String = "111" If StrLenB(test) <> test.Length Then MsgBox("含中文字") Else MsgBox("不含中文字") End If End Sub |
1 2 3 4 5 6 7 8 9 10 11 12 13 | Private Function CharByte(ByVal vstrWord As String) As Integer 'aStr字串之第一個字的位元組長度 If Len(vstrWord) = 0 Then Return 0 Else Select Case Asc(vstrWord) Case 0 To 255 Return 1 Case Else Return 2 End Select End If End Function |
1 2 3 4 5 6 7 8 | Private Function StrLenB(ByVal vstrValue As String) As Integer '如同VB 6.0的LenB函數,傳回字串aStr的位元組長度 Dim i, k As Integer For i = 1 To Len(vstrValue) k += CharByte(Mid(vstrValue, i, 1)) Next Return k End Function |
沒有留言:
張貼留言