Javascript String stripNewline(str)

Description

Javascript String stripNewline(str)

String.prototype.stripNewline = function(str){
    /*from   w w w  .j a v  a 2 s  .c  o m*/
    var trimLoc = this.indexOf("\r\n");
    
    if (trimLoc < 0) {
        trimLoc = this.indexOf("\n");
    }
    
    if (trimLoc < 0) {
        trimLoc = this.indexOf("\r");
    }
    
    if (trimLoc > 0) {
        return this.substring(0, trimLoc)
    }
    
    return this;
}



PreviousNext

Related