VBA 提取中文字符的两个函数

Function RemoveNarrow(str As String) As String
    Set regEx = CreateObject("vbscript.regexp")
    With regEx
        .Global = 1
        .Pattern = "[\x01-\x7f]+"
        RemoveNarrow = .Replace(str, "")
    End With
End Function



Function getCN(str As String) As String

    Dim iAsc As Integer
    Dim char As String * 1
    For i = 1 To Len(str)
        char = Mid(str, i, 1)
        iAsc = Asc(char)
        If (iAsc >= &HAA40 And iAsc <= &HFEA0) Or (iAsc >= &H8140 And iAsc <= &HA0FE) Then
            getCN = getCN & char
        End If
    Next
End Function

摘自ExcelHome

posted on 2012-10-24 10:25  stone.amoi  阅读(2129)  评论(0编辑  收藏  举报