Public Function FilterStr(str_Src As String) As String
    Dim str_Ret As String
    Dim AscCode As Integer
    
    For i = 1 To Len(str_Src)
        AscCode = Asc(Mid$(str_Src, i, 1))
        If (AscCode <> 9 And AscCode <> 13 And AscCode <> 10 And AscCode <> 32 And AscCode <> 0 And AscCode <> -24159) Then
            str_Ret = str_Ret & Chr$(AscCode)
        End If
    Next i
        
    FilterStr = str_Ret
End Function

解决方案 »

  1.   

    去掉以下字符
    9为Tab,10为换行,13为回车,32为空格
      

  2.   

    Public Function FilterStr(str_Src As String) As String //又返回值的函数FilterStr,str_Src为传入的字符串
        Dim str_Ret As String
        Dim AscCode As Integer
        
        For i = 1 To Len(str_Src)    //从1到字符串的长度循环
            AscCode = Asc(Mid$(str_Src, i, 1))    //取每一位的ASCII码(在非 DBCS 系统下,返回值范围为 0 – 255 。在 DBCS 系统下,则为 -32768 – 32767。)
            If (AscCode <> 9 And AscCode <> 13 And AscCode <> 10 And AscCode <> 32 And AscCode <> 0 And AscCode <> -24159) Then    //当前字符如果不符合条件则过滤
                str_Ret = str_Ret & Chr$(AscCode)    //符合条件的字符拼成字符串
            End If
        Next i
            
        FilterStr = str_Ret    //设置函数等于字符串(即返回值为过滤后的字符串)
    End Function