TobyD Posted December 18, 2007 Report Share Posted December 18, 2007 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 Quote Link to comment
Justin Goeres Posted December 18, 2007 Report Share Posted December 18, 2007 QUOTE(TobyD @ Dec 17 2007, 03:59 PM) 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? If you're only ever interested in replacing the last line here's one way: http://lavag.org/old_files/monthly_12_2007/post-2992-1197936683.png' target="_blank"> 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 ). Quote Link to comment
TobyD Posted December 19, 2007 Author Report Share Posted December 19, 2007 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. Quote Link to comment
silmaril Posted December 20, 2007 Report Share Posted December 20, 2007 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 ;-) Quote Link to comment
orko Posted December 28, 2007 Report Share Posted December 28, 2007 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... Quote Link to comment
TobyD Posted January 25, 2008 Author Report Share Posted January 25, 2008 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 ). 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. 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). Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.