LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Last element in string

Solved!
Go to solution

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

 

test.png

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 12
(8,223 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 12
(8,217 Views)

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,

Tom L.
0 Kudos
Message 3 of 12
(8,217 Views)

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.

 

 

 

 

Message 4 of 12
(8,215 Views)

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

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 5 of 12
(8,166 Views)
Solution
Accepted by topic author Nghtcrwlr

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 12
(8,161 Views)

@ 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

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 12
(8,112 Views)

Tim, When are you going to fix your "Favorites" palatte to include the advanced string functions?


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 12
(8,065 Views)

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


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 12
(8,042 Views)

@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 Smiley Wink)


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 12
(8,036 Views)