LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan from string with delimiter (variable length string)

Solved!
Go to solution

Hi,

 

I know there is a simple answer to this question but I cannot seem to find the solution.

 

I have an initial string that is delimited by semicolons. I want to extract string "string" into output 1 and floating point number "12.345" into output 2. Since I put the semicolon seperator in the format string you would think it would scan until it reaches that character but instead output 1 is "string;12.345;% and output 2 fails to produce anything.

 

This format string "%[^;];%f;" will work but seems like a work around to me. Any thoughts?

 

2.JPG

1.JPG

0 Kudos
Message 1 of 10
(5,922 Views)

String length... %<length>s

Period Decimal Separator ( %.; ) before the %f;

 

 


 

 

0 Kudos
Message 2 of 10
(5,910 Views)

Try "not a ;" for your first string. [^;]

 

Try this in your format string

 

%[^;];%f;

Omar
Message 3 of 10
(5,887 Views)

TimeWaveZero: The length of the string varies.

 

Omar_II: I mentioned this in the orignal post but it seems dirty to me. The scan from string functions usually havethe ability to scan a varible length string until it reaches the exact string, which in this case is a semicolon.

0 Kudos
Message 4 of 10
(5,881 Views)

Omar_II wrote:

%[^;];%f;


That is exactly what is needed.  The %[^;] will return a string of variable length up until a ";" is found (not including the ";").  It is not a work around.  It is by design.

 

I highly recommend searching for "Format Specifier Syntax" in the LabVIEW Help.  I keep a printout of that help page hanging in my office since it is such a needed resource.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(5,869 Views)
Solution
Accepted by topic author abeaver

Hi abeaver,

 

ScanFromString scans a variable length string until it reaches a whitespace char (like space, tab, LF, CR)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 10
(5,867 Views)

GerdW wrote:ScanFromString scans a variable length string until it reaches a whitespace char (like space, tab, LF, CR)…

Wow, I did not know that.  I'm not sure if that is good or not.  I guess it hasn't burned me yet.  But something to keep in mind.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 10
(5,861 Views)

@abeaver wrote:

Omar_II: I mentioned this in the orignal post but it seems dirty to me. The scan from string functions usually havethe ability to scan a varible length string until it reaches the exact string, which in this case is a semicolon.


The scan function is what is called "greedy". It will scan using first %s until it finds something that is not a string.

Returning for the first part the longest string the matches. But your string is ALL strings so it grabs all the string to fill the first %s leaving nothing for the rest.

 

Using Regular Expression there is a flag to make it return the shortest string to meet your format string. 

Search for Greedy and non greedy quantifiers.

They might work for the Scan from string function.

 

I almost never use the Scan from String Function for this very reason. I use Regular Expression so that I can control what I get.

Omar
0 Kudos
Message 8 of 10
(5,854 Views)

No need to sell scan from string short.

 

scan number.png

Message 9 of 10
(5,835 Views)

I have used a cheap brute force method to do exactly this:  Run the string through a search and replace function first, and change every instance of your chosen delimiter(s) to whitespace, then scan from string with the normal format specifiers.

 

0 Kudos
Message 10 of 10
(5,663 Views)