Sunday, September 25, 2011

Find last few characters from a string


Share at Facebook

Below is the code that uses substr() function that will return the last three characters from the string. You can change that -3 and 3 parameters according to your need.

First param -3 means start from index 3 from last. And second param 3 means the three characters.


<html><body>

<script type="text/javascript">
var string = "Test String";
string = string.substr(-3, 3);
document.write(string);
</script>

</body></html>


Pretty simple code...




No comments: