LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
NickNZ

Pick Line String Function needs to return a True on Last Line

Every time I want to use the Pick Like String Function, its becuase I want to process a string line by line. 

However its usage is limited by the fact that it does not have a boolean output that goes true on the last line of the string. 

 

This would make it easier to use in a while loop for instance, where the last line can terminate the loop. 

If going past the end of string, it returns an empy string - same as an empty line....

Making the input string a unique string not seen in the file e.g "<EOF>" also doesn't help if a line is empty. 

 

Pick Line.png

 

P.S. Documentation is not clear if the picked line includes the end of line character(s).... It doesn't.

 

So I try to use Pick Line, realise (again) its drawback and then have to think of an alternative... which is easy enough as there are many ways to do it... but my inital thought was not match the end of line character and split the string... 

 

Pick Line work around.png

 

 

8 Comments
crossrulz
Knight of NI

Pick Line is one of those functions I have never found a good use for.  In your example, I would have used Spreadsheet String To Array to get an array of the lines and then I could autoindex a FOR loop.


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
AristosQueue (NI)
NI Employee (retired)

Pick Line really shouldn't be used to parse a multi line string the way you're doing... think about it -- your program is re-reading the entire string, counting EOL characters, every time you call that node. If you're doing that in a loop, split the string into an array of strings once and then use array indexing. OR, more performant, find the index of all the EOL characters in the string and then use string subset.

 

Adding a "last line" output from Pick Line would just encourage more people to use it as you have tried to use it, and that would encourage horribly slow code. It's the wrong tool.

 

Pick Line's utility is, as far as I'm concerned, in really old data structures that have pretty much gone out of use. I've thought several times about suggesting we retire that primitive.

NickNZ
Member

Thanks, good point on the overhead of this call. I now agree its the wrong tool with the "right name" for the programming problem I have. 

 

Its OK for the use I had in mind as string would not be too long, but I could see how it could be miss used and give performance issues.... 

 

Please decline. 🙂  I do think I support retiring pick line...

 

NickNZ
Member

Darren
Proven Zealot
Status changed to: Declined
crossrulz
Knight of NI

You could wire up a 1D array of strings for the array type and the End Of Line Constant or a Line Feed Constant as the delimiter.  Then you have your array of lines.

 

If you are reading from a file, then use the Read From Text File and right-click on it.  There is an option to "Read Lines".  Then set the number of lines to read to -1 to read the entire file as an array of strings (an element for each line).


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
Intaris
Proven Zealot

Use "Scan String for Tokens" instead, it handles really large strings with configurable EOLs rather well.

AristosQueue (NI)
NI Employee (retired)

Intaris is right -- that's the right tool. Unfortunately, Scan String For Tokens is really intimidating to use unless you think like a parser (something no human does naturally).