LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pick the last line of a string

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?

0 Kudos
Message 1 of 17
(4,495 Views)

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":

  • Use SpreadsheetStringToArray to convert your multiline string into an array of strings.
  • Use DeleteFromArray to get the last element/line.

Suggestion: Maybe there are better ways to handle your data than to keep them collected in a multiline string…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 17
(4,487 Views)

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.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 17
(4,483 Views)

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.

0 Kudos
Message 4 of 17
(4,481 Views)

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.

Split String.png 

(That reminds me that I really should fix my LabVIEW ini file.  Those defaults drive me crazy)


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 17
(4,455 Views)

Use match pattern with pattern "[^\n]+$"

0 Kudos
Message 6 of 17
(4,406 Views)

@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.


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 17
(4,396 Views)

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.

0 Kudos
Message 8 of 17
(4,366 Views)

@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.

0 Kudos
Message 9 of 17
(4,358 Views)

0 Kudos
Message 10 of 17
(4,286 Views)