LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Scan String For Tokens" weird behaviour

I am trying to carry out the simple task of getting a string with
comma delimiters and produce a string_array with the values in between
the commas; this would simplify calling the different parts of the
string.

Example:

INPUT: this,is,an,example
OUTPUT: this|is|an|example (this would be an array of strings)

Using a while loop with the two VI "Scan String For Tokens" and
"Insert to array" should be enough to carry this task. I started
using a FOR loop as the number of tokens I´ll be using is fixed.
However I wanted to make the subVI more general by allowing any
#tokens in the input string and using the token index with a WHILE
loop to do this. The "token index" output from the "Scan String For
Tokens" is said to be use
d in a while loop to process the whole
string.

However,I´m getting -1 as an output even if I´ve got more tokens left
and the while loop therefore exits.

What am I doing wrong?
Should I use -2 as the comparison to decide whether I´m at hte end or
not of the string?

Cheers and TIA
0 Kudos
Message 1 of 2
(2,673 Views)
Check the offset for -1, not the token index. (See attached image). If course if this is a multiline string, the you also need /n etc as delimiter.
If the string ends in a delimiter, you need to clip the last array element. I usually use "reshape array" with the output from [n] as input.
0 Kudos
Message 2 of 2
(2,673 Views)