How to separate values

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Topline2012
Newbie
Posts: 8
Joined: Mon Feb 13, 2012 7:55 pm

How to separate values

Post by Topline2012 » Tue Nov 05, 2013 5:27 pm

R74862 60009AG10C9P 0050

I have to separate the above values based on space?? any suggestion pls

hagchr
Automation Wizard
Posts: 328
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Post by hagchr » Tue Nov 05, 2013 5:47 pm

For example:

Let>tmp=R74862 60009AG10C9P 0050
Separate>tmp, ,arrItems

Let>ct=0
While>ctct=ct+1
MessageModal>arrItems_%ct%
EndWhile

hagchr
Automation Wizard
Posts: 328
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Post by hagchr » Tue Nov 05, 2013 5:49 pm

Sorry, something happened when I posted it (looked ok in preview)

Let>tmp=R74862 60009AG10C9P 0050
Separate>tmp, ,arrItems

Let>ct=0
While>ctct=ct+1
Messagemodal>arrItems_%ct%
EndWhile

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Nov 05, 2013 5:57 pm

hagchr,

Highlight the code then click the "Code" button (Just below the "Subject" line)

I also have:

Disable HTML in this post

Disable Smilies in this post
Attach signature (signatures can be changed in profile)
Notify me when a reply is posted


all checked

Code: Select all

Let>tmp=R74862 60009AG10C9P 0050
Separate>tmp, ,arrItems
Let>ct=0
While>ct<arrItems_count
Let>ct=ct+1
MessageModal>arrItems_%ct%
EndWhile

hagchr
Automation Wizard
Posts: 328
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Post by hagchr » Tue Nov 05, 2013 6:06 pm

JRL, many thanks - will help going forward.

Topline2012
Newbie
Posts: 8
Joined: Mon Feb 13, 2012 7:55 pm

Post by Topline2012 » Tue Nov 05, 2013 6:18 pm

thank you

actually the space is about 1 inch between 3 words so i increased the space in separate : Separate>temp1, ,arrItems

hagchr
Automation Wizard
Posts: 328
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Post by hagchr » Tue Nov 05, 2013 6:54 pm

An alternative (for example if you have variable number of spaces between strings) would be to use RegEx

Code: Select all

Let>tmp=R74862       60009AG10C9P    0050

RegEx>[^\s]+,tmp,0,Matches,NumMatches,0,,

Let>ct=0
While>ct<NumMatches
Let>ct=ct+1
Messagemodal>Matches_%ct%
EndWhile

Topline2012
Newbie
Posts: 8
Joined: Mon Feb 13, 2012 7:55 pm

Post by Topline2012 » Tue Nov 05, 2013 7:06 pm

perfect thank you

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Nov 06, 2013 10:54 pm

Hi hagchr,

Nice regex solution... it could also be written like this:

Code: Select all

Let>tmp=R74862       60009AG10C9P    0050

RegEx>[\S]+,tmp,0,Matches,NumMatches,0

Let>ct=0
While>ct<NumMatches
Let>ct=ct+1
Messagemodal>Matches_%ct%
EndWhile
See http://www.regular-expressions.info/shorthand.html and section on Negated Shorthand Character Classes.
info at the link above wrote:\s stands for "whitespace character"... that is: \s matches a space, a tab, a line break, or a form feed.

\S is the negated form of the above... and equivalent to [^\s] inside that character class.
Actually you could dispense with the character class (the [] brackets) completely and just write it as shown below...

Code: Select all

Let>tmp=R74862       60009AG10C9P    0050

RegEx>\S+,tmp,0,Matches,NumMatches,0

Let>ct=0
While>ct<NumMatches
Let>ct=ct+1
Messagemodal>Matches_%ct%
EndWhile
Also in the RegEx> command, if the Replace Flag is 0 then the next two commas are not required at the end... but don't hurt.

Thanks again for this solution... very useful!
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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