有汉字的字符串,SubString防止截断字 Public Shared Function bSubstring(ByVal s As String, ByVal length As Integer) As String Dim bytes As Byte() = System.Text.Encoding.Unicode.GetBytes(s) Dim n As Integer = 0 Dim i As Integer = 0 While i < bytes.GetLength(0) AndAlso n < length If i Mod 2 = 0 Then n += 1 Else If bytes(i) > 0 Then n += 1 End If End If i += 1 End While If i Mod 2 = 1 Then If bytes(i) > 0 Then i = i - 1 Else i = i + 1 End If End If Return System.Text.Encoding.Unicode.GetString(bytes, 0, i) End Function 字符串长度判断 string ss = "名称" ss.Length=2 System.Text.Encoding.Default.GetByteCount"名称")=4 设置千分号(输入123456,显示为123,456) Private Function SetSenText(ByRef txtBox As TextBox) As String Dim cMoto() As Char Dim cSaki() As Char Dim i As Integer Dim j As Integer ReDim cMoto(txtBox.Text.Length) cMoto = txtBox.Text.ToCharArray() ReDim cSaki(0) j = 0 For i = cMoto.Length - 1 To 0 Step -1 j = UBound(cSaki) + 1 ReDim Preserve cSaki(j) cSaki(j) = cMoto(i) j += 1 If j Mod 4 = 0 And i <> 0 Then ReDim Preserve cSaki(j) cSaki(j) = CChar(",") End If Next i ReDim cMoto(0) j = 0 For i = cSaki.Length - 1 To 1 Step -1 cMoto(j) = cSaki(i) j = UBound(cMoto) + 1 ReDim Preserve cMoto(j) Next i Return Convert.ToString(cMoto) End Function Private Function GetSenText(ByRef txtBox As TextBox) As String Dim str As String str = txtBox.Text Return str.Replace(",", "") End Function