LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parsing delimited text

Looking for suggestions on how to parse the following:

str1, str2, str3, str4:

Output would be an array of strings: str1 str2 str 3 str4

Number of strings is variable, I'm done when I see the colon at the end.

I've tried scan for tokens, match pattern, etc, but am having trouble getting things to behave ... any suggestions?

- Rick


0 Kudos
Message 1 of 12
(8,363 Views)
What about Spreadsheet String to Array? Below is the code with a Search and Replace function to remove the ':'.
0 Kudos
Message 2 of 12
(8,357 Views)
EDIT: Posted at nearly same time as Dennis. Didn't see the colon at the end, so stick in that Search and Replace String as Dennis showed, or you can also use Match Pattern to grab the text before the colon.


Message Edited by smercurio_fc on 06-26-2008 10:41 AM
0 Kudos
Message 3 of 12
(8,356 Views)
I'd pass the original string (str1, str2, str3, str4) into Scan from string.vi and parse with (%s, %s, %s, %s) then combine the resulting 4 strings an any manner you wish, i.e. build an array, a cluster, etc...

Good luck

chris
0 Kudos
Message 4 of 12
(8,351 Views)
0 Kudos
Message 5 of 12
(8,348 Views)

cmpowell,

The problem with that is that it cannot handle strings with a variable number of items.

0 Kudos
Message 6 of 12
(8,338 Views)
My bad, forgot to strip the comma off the end, use Match Regular expression.

Good Luck
chris




0 Kudos
Message 7 of 12
(8,334 Views)
Sorry I though you were getting a constant string everytime, you're right that will break scan from string.


0 Kudos
Message 8 of 12
(8,329 Views)
Hi Guys,

Thanks for the ideas.

I probably should have mentioned that this is part of a much larger body of text, like this:

blah blah blah blah (str1;str2, str3: tex1  text2;   str3a, str4: text3 text4;   str5, str6, str7, str8: text5 text6;  etc ...

I have the large body parsed up to and including the open paren and am looking for a way to suck out the str* strings (and place them in an array ..) one set at a time in a loop.

(I also need to pull out the text1 and text2 fields eventually)

Results in each pass of the loop would be:

str1 str2 str3
str3a str4
str5 str6 str7 str8

Note the variable number of strings per group.

Bottom line is I need to know when I hit the colon.




0 Kudos
Message 9 of 12
(8,270 Views)
Never mind, I think I found what I need ...

Scan string for tokens works fin with ", :" as operators.

I get   str1
          ,
          str2
          ,
          str3
           :

Now I can tell when to stop scanning.  Thanks!


0 Kudos
Message 10 of 12
(8,268 Views)