Tuesday, March 30, 2010

strRightBack in javascript

The following is a function equivalent to lotus script's strRightBack function.

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

Illustriation
var x="My Name~ My Friend Name";
alert(strRightBack(x,"~"));    // this will alert " My Friend Name"

Following is a code that will help you extend native javascript's String class with this function

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

Illustriation
var x="My Name~ My Friend Name";
alert(x.strRightBack("~"));    // this will alert " My Friend Name"

1 comment:

  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head.
    I am highly impressed with your blog. It is very nicely explained.
    Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.

    ReplyDelete