I'm searching the fastest way to remove [multiple] blank spaces in a string, to output in a cell afterwards. There can be 1, 2 3, X space characters.
*example: "hello world how are you"*
My process is quite time consuming so i am looking for the fastest way, not necessary the easiest, but my knowledge in vba is limited.
Here is what i found so far:
Regex Removing blank space from a string 'this one is not working for me, even if i add the regex ref. i got a compilation error.
With New RegExp
.Pattern = "\s+"
.Global = True
RemoveExtraSpace = .Replace(inVal, " ")
End With
WorksheetFunction
Application.WorksheetFunction.Trim(s)
EDIT: str = Application.WorksheetFunction.Trim(str) 'seems to work
a for each loop I think this one splits, then reconstruct with one space between each word?
str = Split(s)
s = ""
For Each str1 In str
If str1 <> "" Then
s = s & str1 & " "
End If
Next str1
s = Trim(s)
This one talks about removing ALL spaces
So i am quite confused. I feel like i should use the regEx. Anyone want to share their thoughts on this? Thank you!