05-25-2011 11:12 AM
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
Solved! Go to Solution.
05-25-2011 11:31 AM
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.
05-25-2011 11:32 AM
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
05-25-2011 11:37 AM
Or just a Scan From String with %d,%d,%d,%d as the format specifier.
05-25-2011 11:49 AM
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.
05-25-2011 11:49 AM - edited 05-25-2011 11:52 AM
@johnsold wrote:
Several ways come to mind.
1. One of the regex experts will soon post a method using a regex. [...]
Or me!
05-25-2011 12:01 PM
Sometimes I wonder about these Regexers...
Late to the party, stuck with a more mundane suggestion.
05-25-2011 02:43 PM
Thanks for all the great answers! very informative