I have two strings such as:
sometext~somemoretext~extratext
and
sometext~otherextratext
I wish to crop off the last tilde (~) and all text to the right. For instance, the above two strings would result in:
sometext~somemoretext
and
sometext
Thanks
lastIndexOf(char)returns the position of the last found occurrence of a specified value in a stringsubstring(from, to)extracts the characters from a string, between two specified indices, and returns the new sub stringFor instance:
DEMO
I strongly suggest you to read the doc on the Javascript String Object