如何在字符串中提取中文字符
如何在字符串中提取未知中文字符,如"字符串AJjfgalaf",前提:不知道是否有中文字符并且中文字符未知 问题点数:20、回复次数:8Top
1 楼wangjidh(背土蚂蚁)回复于 2002-10-30 12:51:51 得分 0
一个一个取啊,然后判断每个取得的字符的ARC码是否在英文ARC码范围内,如果不在,默认为中文,保存下来就行了Top
2 楼w18ily(再回首,西门吹沙(学习网络编程))回复于 2002-10-30 14:02:32 得分 20
'Test example:Add a textbox(Text1) On the Form
Private Function isChinese(ByVal asciiv As Integer) As Boolean
If Len(Hex$(asciiv)) > 2 Then
isChinese = True
Else
isChinese = False
End If
End Function
Private Sub Form_Load()
Dim strSource As String
Dim strDestination As String
Dim i As Integer
Dim strSelect As String
strSource = CStr(InputBox("Please input the source string:", "convert"))
strDestination = ""
strSelect = ""
For i = 1 To Len(strSource)
strSelect = Mid(strSource, i, 1)
If isChinese(Asc(strSelect)) Then
strDestination = strDestination + Mid(strSource, i, 1)
End If
Next i
If strDestination = "" Then
MsgBox "没有中文字符!"
Else
Text1.Text = strDestination
End If
End Sub
Top
3 楼mahongliang1983(菜鸟2002)回复于 2002-10-30 14:13:20 得分 0
我觉得ascii好像比较行吧
Top
4 楼dadadou(大豆)回复于 2002-11-01 08:26:32 得分 0
我找到了一个比较简单的方法,VB的字符串是unicode格式的,一个中文字符为一个字节,ascii则是2各字节。len(字符串)=3,lenb(strconv("字符串",vbformunicode))=6.两者相减大于0则有中文字符串,但无法判断中文字符的位置。Top
5 楼w18ily(再回首,西门吹沙(学习网络编程))回复于 2002-11-01 09:11:08 得分 0
楼主,你的目的是什么?Top
6 楼dadadou(大豆)回复于 2002-11-04 13:05:07 得分 0
我想在一个字符串中提取任意位置的中文字符Top
7 楼yenight(抵制日货 利国利民 能不买日货,尽量不买)回复于 2002-11-04 15:43:37 得分 0
asc("char")<0 是一个Unicode字符但不一定是中文如韩文等双字节文字为TrueTop
8 楼dadadou(大豆)回复于 2002-11-12 12:19:23 得分 0
结帐,给w18ily20分。Top





