Pages

Wednesday, March 31, 2010

strRight in javascript

String.prototype.strRight=function(seperator)    {
    //stringValue
    var pos=this.(seperator);
    var result=this.substring(pos+1,this.length)
    return result;
}

alert("xkr".strRight('k'));  // will alert 'r'

function strRightBack(stringValue,seperator)    {
    var pos=stringValue.indexOflastIndexOf(seperator);
    var result=stringValue.substring(pos+1,stringValue.length)
    return result;
}

alert(strRightBack("xkr",'k')); // will alert 'r'

2 comments:

  1. For strRightBack it should be lastIndexOf instead of indexOf, shouldn't it?

    ReplyDelete
  2. Yes thats true. Thank you for pointing it out. I changed it

    ReplyDelete