Need a Ruby script to return the last character in a text string


SWBDesign
 Share

Recommended Posts

I'm trying to create a "Key to Elevations" legend using callouts which are linked to camera views which in turn will populate automatically with the last character of the camera name.

so, a camera with the name of  "Elevation A" would return the value of "A"

 

I need a Ruby Script which can return the last character in the variable "owner.linked_view_name"

I can get a script to return the full name of the "owner.linked_view_name" but I don't know how to parse it down to return just the last character of the returned text string.

 

I typically label all Elevation camera's as Elevation "A,B,C,D....etc"

 

Can anyone help point me in the right direction please?

 

 

Capture.JPG

Link to comment
Share on other sites

On 6/30/2022 at 5:39 PM, SWBDesign said:

Sorted it.

owner.linked_view_name.slice(-1).chr

 

The .chr at the end is unnecessary and redundant.  The chr method will return the first character in the string; however the slice(index) method that you've used will also only return one character, so what you're essentially doing is asking for the character at the -1 index and then asking for the first character of that single character string. 

 

I think the most elegant method is the one Eric showed though. Slice works, but simply calling for the index inside brackets is cleaner. 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share