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,344 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,334 Views)

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

Spread.jpg

0 Kudos
Message 3 of 12
(3,319 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,303 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,293 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,270 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,247 Views)

2013 Version

0 Kudos
Message 8 of 12
(3,236 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,220 Views)

Are you also making use of parrallel for loops?

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