Getting last five characters of a string.

Requirement:

Need to get last 5 characters of a string.

My Thoughts:

Sounds a simple requirement but the place from where I read this requirement had mentions of assigning it to buffer and the finding out the size 😛

When I thought about this requirement the first thing that came to my mind is that it is possible to do this with the help of substring function

Solution:

Wrote a small 3 line script 😀 given below and was able to fulfill the requirement.

    var teststr = “sdfsdfsdfsfjksdhfdsflskdf12345”;
    var len = teststr.length;
    var subs = teststr.substring(len-5);

But then I said to myself is there any other way to do it through configuration or something but was not able to find anything. If you guys know anything that I don’t please let us all know.

Waiting for you comments.

8 Responses to Getting last five characters of a string.

  1. If the value is required for any validations or to populate another field you may consider using Right([fieldName],5) on a calculated value or in any expression like pre/post default value.

  2. If the value is required for any validations or to populate another field you may consider using Right([fieldName],5) on a calculated value or in any expression like pre/post default value.

  3. Right and Left functions work for the above requirement. The Arguments being the FieldValue and the number of characters you need as a sub string.

    NS

  4. Right and Left functions work for the above requirement. The Arguments being the FieldValue and the number of characters you need as a sub string.

    NS

  5. Right and Left functions in the calculated value(for calc fields) work for the above requirement. The Arguments being the FieldValue and the number of characters you need as a sub string.

    NS

  6. Right and Left functions in the calculated value(for calc fields) work for the above requirement. The Arguments being the FieldValue and the number of characters you need as a sub string.

    NS

Leave a Reply

Contribute