Hi!

I am looking for a function that will replace last occurence of a substring from a string:

tmpStr: xxx, yyy, zzz, sss,
The desired outcome: xxx, yyy, zzz and sss
(ie: remove last letter and then replace last occurrence of ",")

The string can differ,
* xxx,
* xxx, yyy,
* xxx, yyy, zzz,

Do anyone of you have a neat fuction for that? I will be so happy for all input!! ;)Thanks in advance!

Member Avatar for Pnorq
var str = "xxx, yyy, zzz, sss,";
if(  str.indexOf( "," ) > 0 && str.indexOf( "," ) != str.lastIndexOf( "," )  ) { // tests for >1 character group in string