当前位置:编程学习 > VB >>

怎么用vb截取中文字符

在一个字符串变量中,有中文字符和英文字符。用什么方法可以把中文字符单独提取出来?
答案:
Public Function SelectChin(iStr As String) As String
Dim s As String, temp As String, i As Integer
For i = 1 To Len(iStr)
    temp = Mid(iStr, i, 1)
    '标准CJK文字
    'CJK统一象形扩展A
    If AscW(temp) >= &H3400 And AscW(temp) <= &H4DB5 Then s = s & temp
    'CJK统一象形字符
    ElseIf AscW(temp) >= &H4E00 And AscW(temp) <= &H9FBB Then s = s & temp
    'CJK兼容象形字符
    ElseIf AscW(temp) >= &HF900 And AscW(temp) <= &HFA2D Then s = s & temp
    'CJK兼容象形字符
    ElseIf AscW(temp) >= &HFA30 And AscW(temp) <= &HFA6A Then s = s & temp
    'CJK兼容象形字符
    ElseIf AscW(temp) >= &HFA70 And AscW(temp) <= &HFAD9 Then s = s & temp
    'CJK统一象形扩展B
    ElseIf AscW(temp) >= &H20000 And AscW(temp) <= &H2A6D6 Then s = s & temp
    'CJK兼容支持
    ElseIf AscW(temp) >= &H2F800 And AscW(temp) <= &H2FA1D Then s = s & temp
    '全角ASCII、全角中英文标点、半宽片假名、半宽平假名、半宽韩文字母:
    ElseIf AscW(temp) >= &HFF00 And AscW(temp) <= &HFFEF Then s = s & temp
    'CJK部首补充
    ElseIf AscW(temp) >= &H2E80 And AscW(temp) <= &H2EFF Then s = s & temp
    'CJK标点符号
    ElseIf AscW(temp) >= &H3000 And AscW(temp) <= &H303F Then s = s & temp
    'CJK笔划
    ElseIf AscW(temp) >= &H31C0 And AscW(temp) <= &H31EF Then s = s & temp
    '康熙部首
    ElseIf AscW(temp) >= &H2F00 And AscW(temp) <= &H2FDF Then s = s & temp
    '汉字结构描述字符
    ElseIf AscW(temp) >= &H2FF0 And AscW(temp) <= &H2FFF Then s = s & temp
    '注音符号
    ElseIf AscW(temp) >= &H3100 And AscW(temp) <= &H312F Then s = s & temp
    '注音符号(闽南语、客家语扩展)
    ElseIf AscW(temp) >= &H31A0 And AscW(temp) <= &H31BF Then s = s & temp
    '日文平假名
    ElseIf AscW(temp) >= &H3040 And AscW(temp) <= &H309F Then s = s & temp
    '日文片假名
    ElseIf AscW(temp) >= &H30A0 And AscW(temp) <= &H30FF Then s = s & temp
    '日文片假名拼音扩展
    ElseIf AscW(temp) >= &H31F0 And AscW(temp) <= &H31FF Then s = s & temp
    '韩文拼音
    ElseIf AscW(temp) >= &HAC00 And AscW(temp) <= &HD7AF Then s = s & temp
    '韩文字母
    ElseIf AscW(temp) >= &H1100 And AscW(temp) <= &H11FF Then s = s & temp
    '韩文兼容字母
    ElseIf AscW(temp) >= &H3130 And AscW(temp) <= &H318F Then s = s & temp
    '太玄经符号
    ElseIf AscW(temp) >= &H1D300 And AscW(temp) <= &H1D35F Then s = s & temp
    '易经六十四卦象
    ElseIf AscW(temp) >= &H4DC0 And AscW(temp) <= &H4DFF Then s = s & temp
    '彝文音节
    ElseIf AscW(temp) >= &HA000 And AscW(temp) <= &HA48F Then s = s & temp
    '彝文部首
    ElseIf AscW(temp) >= &HA490 And AscW(temp) <= &HA4CF Then s = s & temp
    '盲文符号
    ElseIf AscW(temp) >= &H2800 And AscW(temp) <= &H28FF Then s = s & temp
    'CJK字母及月份
    ElseIf AscW(temp) >= &H3200 And AscW(temp) <= &H32FF Then s = s & temp
    'CJK特殊符号(日期合并'
    ElseIf AscW(temp) >= &H3300 And AscW(temp) <= &H33FF Then s = s & temp
    '装饰符号(非CJK专用'
    ElseIf AscW(temp) >= &H2700 And AscW(temp) <= &H27BF Then s = s & temp
    '杂项符号(非CJK专用'
    ElseIf AscW(temp) >= &H2600 And AscW(temp) <= &H26FF Then s = s & temp
    '中文竖排标点
    ElseIf AscW(temp) >= &HFE10 And AscW(temp) <= &HFE1F Then s = s & temp
    'CJK兼容符号(竖排变体、下划线、顿号'
    ElseIf AscW(temp) >= &HFE30 And AscW(temp) <= &HFE4F Then s = s & temp
    End If
Next
SelectChin = s
End Function
调用SelectChin(字符串)函数即可,这个函数你可以根据需要的区间删减ElseIf(或者If)行。

上一个:求一个VB的程序设计
下一个:VB这个程序代码怎么写?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,