This widget could not be displayed.
This widget could not be displayed.

LabVIEW

This widget could not be displayed.
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

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 1 of 12
(4,403 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.

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Message 2 of 12
(4,393 Views)

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

Spread.jpg

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 3 of 12
(4,378 Views)

I've modified your timing setp up slightly.

 

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

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 4 of 12
(4,362 Views)

If your format is never going to change, I like the Scan From String.



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
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 5 of 12
(4,352 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

 

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 6 of 12
(4,329 Views)

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



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
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 7 of 12
(4,306 Views)

2013 Version

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 8 of 12
(4,295 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.

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 9 of 12
(4,279 Views)

Are you also making use of parrallel for loops?

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 10 of 12
(4,273 Views)