10-04-2013 03:16 AM
Hello all
I am having a string like this:
55.000000; 10.000000; 0.100000; 1.000000; 1.000000; 0.100000; 0.000000; 0.000000; 1.000000; 1.000000; 22.000000; 0.100000; 6144.000000;
The length of the string is not always same. What i want is to have the last element. i.e in this case 6144
One way is to get the string length and using string subset to get the last element. But for this, the length must be always constant.
Is there any other way to get the last element independant of the string length
thanks
Solved! Go to Solution.
10-04-2013 03:25 AM
Is the string format always the same?
I see ';' as separators, so you could do a reverse search on this token. Simply take the string after this and format it to a numeric value.
Norbert
10-04-2013 03:29 AM
I'd suggest using the Spreadsheet String to Array function with the delimiter set to "; " and pulling out the last element of the array. Another option would be to reverse the string, truncate at the first semicolon, and re-reverse this subset. There are probably at least a half-dozen other ways to do it with search functions.
Regards,
10-04-2013 03:31 AM
Hi Nghtcrwlr,
below i am attaching the code to remove the last element, it does not depend upon the length of th stirng, you can try this if it works for you.
10-04-2013 07:54 AM
Use the "Match Regular Expression" function from the String palette.
From the LabVIEW help files about Special Characters in Regular Expressions:
$ | Anchors a match at the end of a string when used as the last character of a pattern. For example, dog$ matches dog in the dog but not dog catcher. |
So use $ after your match pattern (for your example, it would be \d+\.\d+$ ). If the semicolon will be there, include it in the match pattern before $, then strip it off after you get the match.
Cameron
10-04-2013 08:07 AM - edited 10-04-2013 08:07 AM
Since you have the extra semicolon at the end, I actually grabbed the second-to-last element of the array after the spreadsheet string to array.
10-07-2013 01:12 AM
@ Nobert: Yes . the string format is always the same. with semicolon as seperators.
@ Cameron: using $ character was quite a new info for me. thanks for the tip. But what if I dont know the last element before searching? Then using a token is not possible, rright?
@ others: thanksyou very much for the help. all answers are working.Thanks
10-07-2013 01:06 PM
Tim, When are you going to fix your "Favorites" palatte to include the advanced string functions?
10-07-2013 03:48 PM
@JÞB wrote:
Tim, When are you going to fix your "Favorites" palatte to include the advanced string functions?
Probably when it becomes officially on the palettes. I work with people who don't like to go off of the beaten path like we do. Maybe when I am finally allowed to set up a user library because I could just make VIPM load the palette for me.
Besides, newbies (ie people asking questions like this) will go digging for it and get majorly lost. I would rather leave that to the intermediate to advanced users.
10-07-2013 03:55 PM - edited 10-07-2013 03:56 PM
@crossrulz wrote:
@JÞB wrote:
Tim, When are you going to fix your "Favorites" palatte to include the advanced string functions?
Probably when it becomes officially on the palettes. I work with people who don't like to go off of the beaten path like we do. Maybe when I am finally allowed to set up a user library because I could just make VIPM load the palette for me.
Besides, newbies (ie people asking questions like this) will go digging for it and get majorly lost. I would rather leave that to the intermediate to advanced users.
with 300+ posts I doubt the OP should be treated as a newbie (Or I wouldn't have picked on you )