vb.net中文符号 vbnet format
vb.net 让相应的textbox中只能输入“中文字符、英文、数字”
每个textbox都有KeyPress事件(event),每次用户输入一个字符时检测,如不满足则清空
创新互联建站主要从事网站设计、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务独山子,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575
我现在不在vs下,你可以找到这个面板,绑定相应的函数
比如只能显示数字
Private Sub NumBox_KeyPress(KeyAscii As Integer)
If Not IsNumeric(NumBox.Text) Then
NumBox.Text = ""
End If
End Sub
只能显示英语(a-z 97-122; A-Z 65-90; 8(退格)和13(换行))
Private Sub EngBox_KeyPress(KeyAscii As Integer)
If Not (KeyAscii = 97 And KeyAscii=122) Or (KeyAscii = 90 And KeyAscii=65) Or = 8 Then
EngBox.Text = ""
End If
End Sub
只能显示汉字(汉字的ASCII值要么小于0,要么是8(退格)和13(换行))
Private Sub ChineseBox_KeyPress(KeyAscii As Integer)
If Not KeyAscii 0 Or KeyAscii = 8 Or KeyAscii = 13 Then
ChineseBox.Text=""
End If
End Sub
做了一些小修改,不明白请及时追问,满意敬请采纳,O(∩_∩)O谢谢
VB.net 如何获得中文字符串的长度?
上面思路是正确的, 用ascw 函数也可以
private function LenC( ps as string ) as Integer
Dim n As Integer
Dim StrLen As Integer
For n = 1 To Len(Text1.Text)
If Ascw(Mid(Text1.Text, n, 1)) 256 Then
StrLen = StrLen + 2
Else
StrLen = StrLen + 1
Next n
return strLen
end function
gb2312>unicode>utf8, 以及逆转的方法'>VB.net 字符转换问题 字符(汉字、数字、字母、符号)>gb2312>unicode>utf8, 以及逆转的方法
字符编码转换吗?
1.字符与gb2312(gbk的子集):
Public Function GBKEncode(ByVal sInput As String) As String
Dim ret_GBKEncode As String = ""
Dim i As Integer
Dim startIndex As Integer = 0
Dim endIndex As Integer
Dim x() As Byte = System.Text.Encoding.Default.GetBytes(sInput) '字符以及字符串在vb2008中都是以unicode编码存储的
endIndex = x.Length - 1
For i = startIndex To endIndex
ret_GBKEncode = "%" Hex(x(i))
Next
Return ret_GBKEncode
End Function
'GBK解码
Public Function GBKDecode(ByVal sInput As String) As String
sInput = sInput.Replace("%", "")
Dim ret_GBKDecode As String = ""
Dim sLen As Integer = sInput.Length
Dim n As Integer = sLen \ 2
Dim sBytes(0 To n - 1) As Byte
'转化为字节码
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))
Next
'将字节码转化为字符串
ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)
Return ret_GBKDecode
End Function
2.Unicode字符串为UTF-8
Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
Return bytes
End Function
'这里可以类推出好几种。
本文标题:vb.net中文符号 vbnet format
网站路径:http://pwwzsj.com/article/doeddid.html