Removing All Spaces in String

后端 未结 7 1441
滥情空心
滥情空心 2021-01-11 13:33

I created a macro for removing all whitespace in a string, specifically an email address. However it only removes about 95% of the whitespace, and leaves a few.

My c

7条回答
  •  清歌不尽
    2021-01-11 14:00

    Space Problem with Excel ok, the only way i see this two types of space is by converting their Ascii code value of which I do it here now to explain this function i made, it will just filter the string character by character checking if its equal to the two types of space i mentioned. if not it will concatenate that character into the string which will be the final value after the loop. hope this helps. Thanks.

    Function spaceremove(strs) As String
    Dim str As String
    Dim nstr As String
    Dim sstr As String
    Dim x As Integer
    str = strs
    
    For x = 1 To VBA.Len(str)
        sstr = Left(Mid(str, x), 1)
        If sstr = " " Or sstr = " " Then
        Else
            nstr = nstr & "" & sstr
        End If
    
    Next x
    spaceremove = nstr
    End Function
    

提交回复
热议问题