12-13-2022 05:43 AM
hello, i have a multiple line string which, everytime i run the program, writes 2 more lines with some parameters. What i need to do is take the last line of the string and strip it from the rest to write more code on it. I tried to use the pick line function but it doesnt really work because every time i run the program the number of lines increases, so the number i wrote as an imput to the function isnt the last line anymore. How can i do that?
12-13-2022 05:58 AM
Hi dom,
@domcorrado wrote:
What i need to do is take the last line of the string and strip it from the rest to write more code on it.
Solve your request "word by word":
Suggestion: Maybe there are better ways to handle your data than to keep them collected in a multiline string…
12-13-2022 06:01 AM
Hello Domcorrado,
It is always better to share the data (Multi line String data) and piece of code you have tried, so that we can provide better suggestion.
For now you can convert this multi line string to array based on Delimiter and can fetch the last element for your processing.
12-13-2022 06:02 AM
Use match pattern function to search for EOL/CR/LF constant (depending on which you insert into your strings) and then loop until "after substring" returns empty string and return previous string.
12-13-2022 06:42 AM - edited 12-13-2022 06:48 AM
If you look in VI.lib \ Advanced String\ you find "Split String.vi" (Also exposed in the "Hidden Gems TK" by Darren Nattinger of NI.) That vi and its friends are extremely useful.
Here's a snippet of a use case for you.
(That reminds me that I really should fix my LabVIEW ini file. Those defaults drive me crazy)
12-13-2022 08:13 AM
Use match pattern with pattern "[^\n]+$"
12-13-2022 08:42 AM
@Martin_Henz wrote:
Use match pattern with pattern "[^\n]+$"
You cannot anchor with Match Pattern. You would need Match Regular Expression which performs slowly because it recurses so you don't have to curse.
12-13-2022 10:11 AM
Maybe it is more efficient to reverse the string, then search for the new line character from the end, then reverse the result if you really just want only the last line.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
12-13-2022 10:30 AM
@domcorrado wrote:
hello, i have a multiple line string which, everytime i run the program, writes 2 more lines with some parameters. What i need to do is take the last line of the string and strip it from the rest to write more code on it. I tried to use the pick line function but it doesnt really work because every time i run the program the number of lines increases, so the number i wrote as an imput to the function isnt the last line anymore. How can i do that?
While you got plenty of advice already, maybe a better solution is upstream. Why do you run the program multiple times? That is unusual, because a proper state machine should always run. Where does it keep the ever-growing string? (Uninitialized shift register?(good!) local variable ping-pong? (bad!), value property node ping-pong? (even worse!), a text file? (OK), etc.)
If you correctly keep the string in a shift register, just add another shift register to keep track of the insert point.
Maybe you can edit the two incoming lines before they are added to the string, avoiding all the complications.
Where do the "two lines" come from?
I suggest that you show us your code to avoid all ambiguities. I am sure we can show you had to do things correctly.
12-14-2022 02:59 AM
@JÞB: out of curiosity: these code snippets are supposed to be brought back into LV code, but how? NI has a tutorial, but for me it doesn't work. I can create such snippets but not vice versa. Dragging it from here into the front panel or block diagram only creates a hyperlink. Saving the snippet an PNG and dragging into LV, as the tutorial describes, would only place an image. How do you do it?