From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to fast split a string in sub-strings

Solved!
Go to solution

Hello,

i have a string with 8 fields divided with a separator. For example:

C|text|20140910-132435|1|A|0,000|0,000|3

 

Currently i use "MatchPattern" to split this string into the fields.

For 200.000 loops it akes ~1sec

 

Can this be done faster?

Thanks

 

show.jpg

0 Kudos
Message 1 of 12
(3,342 Views)

Maybe simpler would be to use spreadsheet string to array with '|' as delimiter. Array type 1D-array of strings.

I wouldn't expect this method to be faster, though.

Message 2 of 12
(3,332 Views)

Thanks. I tested it but ist 0.4sec slower against MatchPattern.

Spread.jpg

0 Kudos
Message 3 of 12
(3,317 Views)

I've modified your timing setp up slightly.

 

There's no need to subtract and update the indicator 20k times.

0 Kudos
Message 4 of 12
(3,301 Views)

If your format is never going to change, I like the 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
0 Kudos
Message 5 of 12
(3,291 Views)

@Richard_Ha

I can only open Vi´s Labview 2013 😞

@

How to set the format-string for ScanFromString? %s|%s|%s|%u|%s|%f|%f|%u is not working, how do i set the separator here?

 

Thanks

 

0 Kudos
Message 6 of 12
(3,268 Views)

Use "[^|]" for the strings.  That will give you a string up to (but not including) the |.


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 12
(3,245 Views)

2013 Version

0 Kudos
Message 8 of 12
(3,234 Views)

Simply moving the string to number conversions outside the loop reduced time by a factor of 3 on my system (280ms for your code to 90ms).  I had to replace the scan from string to fract/exp string to number, but the string functions will take arrays and output arrays.

 

EDIT:  I also moved the timing calculation to a frame after the for loop to remove the needless update of the indicator for my numbers above.

0 Kudos
Message 9 of 12
(3,218 Views)

Are you also making use of parrallel for loops?

0 Kudos
Message 10 of 12
(3,212 Views)