Jump to content

Overwrite Line in Multiline String Indicator


TobyD

Recommended Posts

I am using a multiline string indicator to display test information as it happens. I occasionally need to overwrite the last line of the indicator. For example one test runs 50 times, so I display:

Executing test XXX - Run 01 of 50

I then overwrite that line with:

Executing test XXX - Run 02 of 50

etc.

For now, I use the OpenG VIs to convert my string to a 1D array, overwrite the last element, and then convert it back into a string. I have attached my current method, but I'm thinking that there could be a more efficient way...any ideas?

Thanks,

Toby

post-8758-1197932266.png?width=400

Link to comment

QUOTE(Justin Goeres @ Dec 17 2007, 04:13 PM)

If you're only ever interested in replacing the last line here's one way:

Note that you'll have to change the constant 0 to a 1 if your string already terminates with a CRLF (or do something slightly more elegant in general :) ).

Side Note: I wish the Pick Line function would take negative line numbers, where e.g. -1 would give you the last line of the input string, -2 would give the second-to-last, etc.

That's creative, I like it. I was trying to come up with a way to use the Pick Line function, but all I had come up with was iterating through each line until the output was equal to the string to append (indicating you have passed the last line). It would be nice if there was a function that would return the number of lines in a multiline string or, like you mentioned, if this one would accept negative numbers.

Link to comment

QUOTE(TobyD @ Dec 18 2007, 05:41 PM)

It would be nice if there was a function that would return the number of lines in a multiline string or, like you mentioned, if this one would accept negative numbers.

I think the problem is that there is no simple way of determining how many lines a string has. The only way is to analyse all of the data and count the EOLs you find.

This is not very efficient for large strings, no matter if you do it in your own LV code or hide it inside a LV primitive.

If you are looking for an efficient way to replace the last line several times, I suggest you find the position of the last EOL an remember it. Then you can replace the string section starting from this position several times.

An even easier way would be to remember the complete string before adding the last line. Then you can always add you new last line to this string and write it to your indicator. This has the drawback of using more memory. If this should bother you depends on the size of your string and the RAM in your computer ;-)

Link to comment
  • 2 weeks later...

QUOTE(Justin Goeres @ Dec 17 2007, 04:13 PM)

Side Note: I wish the Pick Line function would take negative line numbers, where e.g. -1 would give you the last line of the input string, -2 would give the second-to-last, etc.

This functionality would be very benificial. Other scripting languages (Perl) handle substrings in this manner, where a negative number in the index switches to start at the end of the string. Of course, you can get the same by reversing the string, then reversing again after the substring is extracted, but a negative number would be oh so nice to use again...

Link to comment
  • 4 weeks later...

QUOTE(Justin Goeres @ Dec 17 2007, 04:13 PM)

If you're only ever interested in replacing the last line here's one way:

post-2992-1197936683.png?width=400

Note that you'll have to change the constant 0 to a 1 if your string already terminates with a CRLF (or do something slightly more elegant in general :) ).

I found a bug in this implementation so I thought I'd post the fix back here in case anyone else needs this code in the future. The example above works fine if every line is unique. However, if your string contains identical lines, any data past the first instance of that line will be lost. By keeping the string reversed when you call Match Pattern you will find the match closest to the end of the original input string.

post-8758-1201214336.png?width=400

Note: The constant wired to Pick Line is the index of the line you want to replace - counting up from the last line in your multiline string (Last Line=0, Second to Last Line = 1, Etc).

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.