LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan from string node question

Hi community,

 

I have an input string in which I have numbers between the <ele> and <\ele> tags. I'd like to extract all these numbers into a numeric array. While I have no problem to realize this function with some of the basic VIs of LabVIEW, somehow I have a gut feeling that there is a more elegant way to do it (maybe using the scan from string node)

 

I have attached the screenshot of my current solution. Please advise.

 

Thanks,

i-

0 Kudos
Message 1 of 5
(2,635 Views)

Not much more condensed, but this is how you should do it with Scan From String.


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
Message 2 of 5
(2,625 Views)

My solution works completely fine, but I believe the scan from string method is more intuitive as it is more visible what are we exactly searching for in the format options input. (so whoever reads the code doesnt have to put the pieces together like in my version)

 

Kudos!

0 Kudos
Message 3 of 5
(2,581 Views)

Personally I prefer using regular expressions for matching. They are much more flexible. Notice this will work for various forms of the input. In addition, the code below uses fewer operations (no need for a second or third pattern match. You do end up with an extra element at the end of the array but that is easy to strip off.

 

Basic XML regex for numbers.png



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 4 of 5
(2,555 Views)

Using Mark solution you can use the conditional tunnel mode to avoid the last empty element.

 

remove last empty element.png

Message 5 of 5
(2,508 Views)