LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multi-line string -> Array?

I was wondering if someone could tell me how to take a multi-line
string and dump it into an array. I'm assuming that I use the 'Pick
Line' function in a while loop? What do I check for to terminate the
loop?

Thanks...

-- N
0 Kudos
Message 1 of 8
(18,165 Views)

Attached is a sample vi.

 

*Note: There is a bug in the attached VI. This solution works only if your input string does not include any blank lines. This will stop after the first blank line.

 

[edited by moderator to add note 07/13-2015]

Message 2 of 8
(18,165 Views)
You could use spreadsheet string to array. Wire a line feed constant to the
delimiter input, an empty string array constant to the array type input, and
a %s to the format input.
Adam

"Natalia" wrote in message
news:99e216d.0210171408.22a87ca0@posting.google.com...
> I was wondering if someone could tell me how to take a multi-line
> string and dump it into an array. I'm assuming that I use the 'Pick
> Line' function in a while loop? What do I check for to terminate the
> loop?
>
> Thanks...
>
> -- N
Message 3 of 8
(18,165 Views)
In article <99e216d.0210171408.22a87ca0@posting.google.com>, "Natalia"
wrote:

> I was wondering if someone could tell me how to take a multi-line string
> and dump it into an array. I'm assuming that I use the 'Pick Line'
> function in a while loop? What do I check for to terminate the loop?
>
> Thanks...
>
> -- N

Natalia,

Use the 'Spreadsheet String to Array' vi. Use the End of Line delimiter
(or carriage return, depends on OS). Add a %s to the format string and
POOF!, an instant text array. No loops required. Oh yeah, you also need
to add an array string constant to the array type so the output comes out
as a string type instead of the default double.

You can do it with you present method if you need the loops for other
stuff.
To terminate the loop just look for a -1 in the output of 'Pick
Line' when searching for you CR or EOL. You just have to remember to dump
the last value.

good luck,
- Kevin
0 Kudos
Message 4 of 8
(18,165 Views)
"kevin" wrote in message news:...
> In article <99e216d.0210171408.22a87ca0@posting.google.com>, "Natalia"
> wrote:
>
> > I was wondering if someone could tell me how to take a multi-line string
> > and dump it into an array. I'm assuming that I use the 'Pick Line'
> > function in a while loop? What do I check for to terminate the loop?
> >
> > Thanks...
> >
> > -- N
>
> Natalia,
>
> Use the 'Spreadsheet String to Array' vi. Use the End of Line delimiter
> (or carriage return, depends on OS). Add a %s to the format string and
> POOF!, an instant text array. No loops required. Oh yeah, you also need
> to add an array string constant to the array type so the output comes ou
t
> as a string type instead of the default double.
>
> You can do it with you present method if you need the loops for other
> stuff. To terminate the loop just look for a -1 in the output of 'Pick
> Line' when searching for you CR or EOL. You just have to remember to dump
> the last value.
>
> good luck,
> - Kevin

Kevin -

Thank you. That did the trick.

-- Natalia
0 Kudos
Message 5 of 8
(18,165 Views)

siddesh_yadav_0-1626088525480.png

 

0 Kudos
Message 6 of 8
(6,053 Views)

Hi siddesh,

 

welcome to the LabVIEW forum!

 

What's your point to add an image of a possible solution to a 19+ years old thread?

Why don't you attach the VI or atleast a snippet?

Why did you implement a more complicated solution than needed?

Why don't you follow those suggestions to use SpreadsheetStringToArray? No need to use a loop and an autoindexing tunnel for this purpose…

 

More simple:

(This is a snippet, which shows an image, but still contains the code!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 8
(6,049 Views)

@siddesh_yadav wrote:

siddesh_yadav_0-1626088525480.png

 


This also assumes array elements are not empty. It stops at the first empty element...

 

Typically, any manual solution is orders of magnitude slower then Spreadsheet String To Array.

0 Kudos
Message 8 of 8
(6,010 Views)