Jump to content

[SOLVED] strip character from string?


ballhogjoni

Recommended Posts

in this instance the last character.

 

Please be specific. Are you wanting to remove the letter "s" in any string where the word "clubs" exists? Are you wanting to remove the last letter from a string? Are you wanting to remove the letter "s" from any string?

 

Give some details as to what you are trying to accomplish - exactly. substr() would be one possible solution based upon certain parameters. In others it may be inefficient or not even appropriate to use.

Where "string" is the string variable:

string.replace(/clubs$/i, 'club');

 

That will change "clubs" or "Clubs" (or any case variations, i.e. it is case insensitive) to "club" if those matches occur at the very end of the string.

 

If you maintain the case of the word, someone else might have a simple replace() solution. I could do it, but would take a few more lines of code using a match() and then rebuilding the string. If you need to maintiain case, please state so.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.