Skip to main content
Solved

How can keep only the last character from a string.

  • October 16, 2013
  • 2 replies
  • 548 views

Hi,

 

 

I'm trying to create an attribute that is simply the final character of another attribute. Using the substring extractor I can remove the final character with and stand and end on 0 and -2, and I can extract a character at a known location with 18, 19. The length of string hoewever vary so I need to find a way of dealing wit the last character rather than the xth. Is there another combination of start and end index that will allow me to do this or do I need another transformer?

 

 

Thanks

Best answer by kim

Negative values are calculated from the end of the string. Perhaps use a start of -1 and end of -1?
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

Forum|alt.badge.img+5
  • Best Answer
  • October 16, 2013
Negative values are calculated from the end of the string. Perhaps use a start of -1 and end of -1?

Forum|alt.badge.img
  • October 17, 2013
You can as well extract this last character using a StringSearcher with a Regular Expression: (.){1}$.

 

 

The dot means any character (except new lines)

 

The number in curly brackets indicates the number of characters you want to get

 

the dollar sign means the end of the string

 

 

In our case the expression would match the any 1 character before the end of the string (i.e.: the end of the string)