Remove multiple spaces from text

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
stuartworley
Newbie
Posts: 2
Joined: Tue Jun 14, 2005 2:43 pm

Remove multiple spaces from text

Post by stuartworley » Tue Jun 14, 2005 2:49 pm

I have a line of text from the clipboard that contains four numbers separated by a variable number of spaces. I need to parse these numbers into four variables.

I tried using the separate command, but no luck. I either get one variable with the entire string or a variable for each character.

Thanks

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Jun 14, 2005 3:04 pm

Regular Expressions will do this. "\s+" means any number of space characters. So the following function replaces whitespace with any single character of your choice. In the example below I replace whitespace with one single space character. E.g. any number of spaces together are replaced with one space character:

VBSTART
Function ReplWhiteSpace(strng,replchar)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "\s+"
regEx.Global = True
ReplWhiteSpace = regEx.Replace(strng,replchar)
End Function
VBEND
Let>Line=Hello How Are you today?
VBEval>ReplWhiteSpace("%Line%"," "),newval

Once you've done this it will be easy to use Separate to extract each part separated by the space (or whatever delimiter you choose to pass in as the second parameter of ReplWhiteSpace).
MJT Net Support
[email protected]

stuartworley
Newbie
Posts: 2
Joined: Tue Jun 14, 2005 2:43 pm

Post by stuartworley » Tue Jun 14, 2005 4:11 pm

Thanks, works great.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts