mubi_masti
Registered User.
- Local time
- Today, 16:53
- Joined
- Oct 2, 2011
- Messages
- 46
Public Function RemoveSpaces(ByVal strField As String) As String
If InStr(strField, Chr(160)) > 0 Then
RemoveSpaces = Replace(strField, Chr(160), "")
ElseIf InStr(strField, Chr(32)) > 0 Then
RemoveSpaces = Replace(strField, Chr(32), "")
Else
RemoveSpaces = strField
End If
End Function
ElseIf InStr(strField, Chr(32)) > 0 Then
RemoveSpaces = Replace(strField, Chr(32), "")
Public Function True_Trim(strText As String) As String
On Error GoTo Error_Handler
strText = Trim(strText)
strText = Replace(strText, Chr(160), "")
Exit_Function:
On Error Resume Next
True_Trim = strText
Exit Function
Error_Handler:
msgbox Err.Description
strText = ""
Resume Exit_Function
End Function
What benefit would this give?Wouldn't you want the Replace before the Trim?![]()
The Trim takes care of chr(32)Well if the hard space is in the front or back of the string, it would not get trimmed?
However on examining your "" a little closer, it seems there is not a space between each character. I initially thought there was.
Also what happens if it happens to be Chr(32)?
Hi. Welcome to AWF!The Trim takes care of chr(32)
Hi,Hi. Welcome to AWF!
What about the possibility of having soft spaces between hard (non-breaking) spaces, like what @Gasman mentioned? Was that possible?
strText = Replace(strText, Chr(32), "")
strText = Replace(strText, Chr(160), "")
strText = Replace(Replace(strText, Chr(32), ""), Chr(160), "")
strText = Replace(strText, Chr(32), "")
strText = Replace(strText, Chr(160), "")
strText = Replace(strText, Chr(160), chr(32))
strText = Trim(strText)
strText = chr(160) & "abc xyz "
=> "abcxyz"
vs "abc xyz"
Hi Josef,In the name of a function that removes all spaces (32,160,...), I would not use "Trim", which only trims at the beginning and end.
vs.Code:strText = Replace(strText, Chr(32), "") strText = Replace(strText, Chr(160), "")
Code:strText = Replace(strText, Chr(160), chr(32)) strText = Trim(strText)
.. eg:strText = chr(160) & "abc xyz "
=>"abcxyz"
vs"abc xyz"