ballhogjoni Posted January 21, 2009 Share Posted January 21, 2009 How do I strip the character "s" from the string "Clubs"? Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/ Share on other sites More sharing options...
Mchl Posted January 21, 2009 Share Posted January 21, 2009 Do you mean 'strip last character' or 'strip s' ? Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/#findComment-742357 Share on other sites More sharing options...
ballhogjoni Posted January 21, 2009 Author Share Posted January 21, 2009 in this instance the last character. Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/#findComment-742447 Share on other sites More sharing options...
Mchl Posted January 21, 2009 Share Posted January 21, 2009 substr Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/#findComment-742455 Share on other sites More sharing options...
Psycho Posted January 21, 2009 Share Posted January 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/#findComment-742461 Share on other sites More sharing options...
Maq Posted January 21, 2009 Share Posted January 21, 2009 in this instance the last character. What about every instance? Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/#findComment-742463 Share on other sites More sharing options...
ballhogjoni Posted January 21, 2009 Author Share Posted January 21, 2009 I want to remove the letter "s" in any string where the word "clubs" exists but it has to be the last letter. Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/#findComment-742507 Share on other sites More sharing options...
Psycho Posted January 21, 2009 Share Posted January 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141794-solved-strip-character-from-string/#findComment-742544 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.