Nodejs String Trim Left ltrim()

Here you can find the source of ltrim()

Method Source Code

/**/*w  w  w .  j  a  v a 2 s  . co  m*/
@Name: String.prototype.ltrim
@Author: Paul Visco
@Version: 1.0 11/19/07
@Description: Trims all white space off the right side of a string
@Return: String The original text with whitespace removed from the right
@Example:
var myString = 'hello              ';

var newString = myString.rtrim();
//newString = 'hello';
*/
String.prototype.ltrim = function(){
   return this.replace(/\s+$/, "");
};

Related

  1. ltrim()
    var s1 = new String('  A  B  ');
    String.prototype.ltrim = function(){
      var regexp = /^\s*/;
      var result = this.replace(regexp, '');
      return result;
    };
    console.log('||'+s1.ltrim()+'||');
    
  2. ltrim()
    String.prototype.ltrim = function() {
      return this.replace(/^\s*/g,'');
    
  3. ltrim()
    String.prototype.ltrim=function()
      return this.replace(/(^\s*)/g,'');
    
  4. ltrim()
    String.prototype.ltrim = function() {
      return this.replace(/(^\s*)/g, "");
    
  5. ltrim()
    String.prototype.ltrim = function() {
      return this.replace(/^\s+/,'');
    
  6. ltrim()
    String.prototype.ltrim = function(){
      return this.replace(/^\s+/, "");
    };
    
  7. ltrim()
    String.prototype.ltrim = function()
      return this.replace( /^\s*/g, '' ) ;
    
  8. ltrim()
    String.prototype.ltrim = function(){
        var res = this;
        while (res.substring(0, 1) == " ") {
            res = res.substring(1, res.length);
        return res;
    
  9. ltrim()
    String.prototype.ltrim=function()
      {return this.replace(/^\s+/,'');}