VBA 判断字符串含中文、英文、数字(亲自实践)

时间:2025-02-14 19:46:49
        length = 0
        tmpExp = ""
       
        exp = Trim(xlsheet_TandE.cells(i, 8))
        For j = 1 To Len(exp)
           
            temp = Mid(exp, j, 1)
            '判断是否是中文
            If temp Like "[一-龥]" Then
                '截取前26个半角字符
                If length + 2 > 26 Then
                    Exit For
                Else
                    length = length + 2
                    tmpExp = tmpExp & temp
                End If
               
            '判断是否是英文、数字、英文半角句号和空格
            ElseIf temp Like "[0-9a-zA-Z. ]" Then
                '截取前26个半角字符
                If length + 1 > 26 Then
                    Exit For
                Else
                    length = length + 1
                    tmpExp = tmpExp & temp
                End If
               
            End If
        Next j
       
        '将截取后的内容设定到"Explaination"中
        xlsheet_TandE.cells(i, 8) = tmpExp