LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan From String Madness

Solved!
Go to solution

This:

s1.png Yields 3 strings: "ABC", "DEF", "GHI".

 

Whereas this:

s2.png  Yields 3 strings: "ABC", "GHI", "", and an error.  WHY?  (Oh I know there's a reason, just not a good one).

Of course there are lots of ways to parse out the string so the double new-line would yield a null string in the middle, but is there a trick to get Scan From String to do it nicely?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 1 of 7
(1,404 Views)

I'm guessing it has to do with how LabVIEW treats "whitespace". Looking into the "trim whitespace.vi" it uses regex to look for tabs, space, carriage return and newlines AND any number of them. Two newlines are probably treated as a single entry of "whitespace".

 

Screenshot 2021-05-03 174512.png

 

You've probably figured a way around, but here's one that specifically looks for each newline character and splits the string by that.

Split string by newline LV2020.png

 

 

0 Kudos
Message 2 of 7
(1,370 Views)

@paul_cardinale wrote:

This:

s1.png Yields 3 strings: "ABC", "DEF", "GHI".

 

Whereas this:

s2.png  Yields 3 strings: "ABC", "GHI", "", and an error.  WHY?  (Oh I know there's a reason, just not a good one).

Of course there are lots of ways to parse out the string so the double new-line would yield a null string in the middle, but is there a trick to get Scan From String to do it nicely?


I think this might have actually worked in LV 2012.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 7
(1,330 Views)

This works, it's just a lot messier than Scan From String would be:

s3.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 7
(1,311 Views)
Solution
Accepted by paul_cardinale

A regex with submatches also works:

regex-match.png




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
Message 5 of 7
(1,267 Views)

@paul_cardinale wrote:

but is there a trick to get Scan From String to do it nicely?


s1.PNG

Message 6 of 7
(1,249 Views)

wiebe@CARYA wrote:

@paul_cardinale wrote:

but is there a trick to get Scan From String to do it nicely?


s1.PNG


Doesn't handle blank lines.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 7
(1,216 Views)