LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

split/search string function

Solved!
Go to solution

I'm using the search/split string function to extract part of a string. My string is in this format: "2005,31,19,47" There will always be 4 numbers separated by commas, however, they will not always be the same number of digits as here. I need to get the fourth number, in this case 47. I can't just search for "," and use an offset because the numbers are not always each this same length. Is there any way to search for the third comma? Thanks

0 Kudos
Message 1 of 8
(4,922 Views)
Solution
Accepted by topic author ENGRLAB

Hi Engrlab

 

One way to do this is to use the 'Scan from String' function with the format string set to "%f,%f,%f,%f". This pretty much tells LabVIEW that there are four floating point numbers separated by three commas with quotes all around.

Please see the enclosed snippet for the solution.

Senior Software Engineer
www.Adansor.com
Message 2 of 8
(4,912 Views)

Several ways come to mind.

 

1.  One of the regex experts will soon post a method using a regex.

2. Use 3 Match pattern Functions, matching the comma, and feeding the String After Match to the input of the next function.

3. Use Match pattern in a loop with the Offset past Match fed back via a shift register.

 

Lynn

Message 3 of 8
(4,908 Views)

Or just a Scan From String with %d,%d,%d,%d as the format specifier.

Message 4 of 8
(4,901 Views)

You can also use a regular expression. I find this is more flexible than the scan from string. The regular expression "(\d*),(\d*),(\d*),(\d*)" would work. The nice thing about regular expressions is that you can be more creative about the format of the number (you can match both integers and floating point) and be more flexible about what separates the numbers. I have found the Scan from String to be very picky and it is very easy to have input strings not work as expected.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 8
(4,890 Views)

@johnsold wrote:

Several ways come to mind.

 

1.  One of the regex experts will soon post a method using a regex. [...]


Or me!

 

regex.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 6 of 8
(4,889 Views)

Sometimes I wonder about these Regexers... Smiley Tongue

 

Late to the party, stuck with a more mundane suggestion.

 

SimpleSpreadsheetString.png

Message 7 of 8
(4,876 Views)

Thanks for all the great answers! very informative

0 Kudos
Message 8 of 8
(4,856 Views)