Javascript String trim() method 2

Description

Javascript String trim() method 2

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

Javascript String trim()

// Monkey patch String to support a trim() method...
// http://snippets.dzone.com/posts/show/701
String.prototype.trim = function() { 
  return this.replace(/^\s+|\s+$/, '');
}

Javascript String trim()

String.prototype.trim = function(){
  return this.replace(/^\s+|\s+$/g, "");
};

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

Javascript String trim()

String.prototype.trim = function(){
    return this.replace(/(^[\\s]*)|([\\s]*$)/g, "");
}

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, '');
}

Javascript String trim()

String.prototype.trim = function(){
  var t = this.replace(/(^\s*)|(\s*$)/g,""); 
  return t.replace(/(^\u3000*)|(\u3000*$)/g,"");
};
function killErrors(){
  return true;//w  w  w . j  a  va 2s  .  c  om
}
//window.onerror = killErrors;

Javascript String trim()

String.prototype.trim=function(){
  var m=this.replace(/(^[\s]*)|([\s]*$)/g,"");
  return m;/*  ww  w  . ja  va2s  .  c  o  m*/
}

Javascript String trim()

String.prototype.trim || (String.prototype.trim = function() {
    var str = this.replace(/^\s\s*/, ''),
        ws = /\s/,// ww  w.  j a v  a  2 s  . co  m
        i = str.length;

    while(ws.test(str.charAt(--i)));

    return str.slice(0, i + 1);
});

Javascript String trim()

'use strict';//from w w w  . j  a v a 2  s .c  om

String.prototype.trim = function(){
  return /^\s*([\d\D]*?)\s*$/.exec(this)[1];
};

Javascript String trim()

"use strict";//Just don't cross the streams!!

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

Javascript String trim()

// Copyright (c) Tanzim Saqib. All rights reserved.
// For continued development and updates, visit http://TanzimSaqib.com

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

Javascript String trim()

String.prototype.trim = function() {
  // skip leading and trailing whitespace
  // and return everything in between
  var x=this;/*from   www  . j  a va 2 s  . c  o  m*/
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

Javascript String trim()

js_strict(true);//  w  ww  .  ja  v a 2 s .c  o  m

String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, ''); };

Javascript String trim()

String.prototype.trim = function() {
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");
}

Javascript String trim()

// String.prototype.trim
String.prototype.trim = function trim() {
  return this.replace(/^\s+|\s+$/g, '');
};

Javascript String trim()

String.prototype.trim = function trim() {
  return this.replace(/^\s+|\s+$/g, '');
};

Javascript String trim()

String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, ''); 
};

Javascript String trim()

String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g, "");
};

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

Javascript String trim()

String.prototype.trim = function(){
  return this.replace(/^(\s|\u00A0)+/,'').replace(/(\s|\u00A0)+$/,'');   
}

Javascript String trim()

String.prototype.trim = function () {
  return this.replace(/(^\s*)|(\s*$)/gi, "");
};

Javascript String trim()

String.prototype.trim = function() {
  var trimmed = this.replace(/^\s+|\s+$/g, "");
  return trimmed;
};

Javascript String trim()

// Trim/* www .  j  a va 2  s  . co  m*/
String.prototype.trim = function () {
  return this.replace(/^\s+|\s+$/g, "");
}

Javascript String trim()

String.prototype.trim = function() {
  return this.replace(/^\s|\s$/, "");
};

Javascript String trim()

String.prototype.trim = function () {
  return this.replace(/^[\s\xA0]+|[\s\xA0]+$/g, '');
};

Javascript String trim()

String.prototype.trim = function() {
  return this.replace(/^\s+/,'').replace(/\s+$/,'');
};
console.log(JSON.stringify("  foo  ".trim()));

Javascript String trim()

String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '')
}

Javascript String trim()

String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/, "");
};

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/, "");
}

Javascript String trim()

String.prototype.trim = function() {
  return this.replace("/(*)|(\s*$))/g",'')
};

Javascript String trim()

String.prototype.trim = function(){
  return this.replace(/(^\s+)|(\s+$)/g,'')
}

var a = "  bala  bala  "
console.log(a);/* www.  j a  v a  2 s .  com*/
console.log(a.trim());

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/+|s+$/, '');
}

function validate(input) {
    alert(1);/*from   w  ww .  j a v a 2 s.c om*/
}

Javascript String trim()

/**/*w w  w.  j ava  2  s  .  c  om*/
 * trim is a Method of String to remove all before and after whitespace
 * @return     a String, result of fitering before and after whitespace
 */
String.prototype.trim = function()
{
  return this.replace(/^\s*|\s*$/g, '');
};

Javascript String trim()

String.prototype.trim = function () {
    return this.replace(/^\s*/,"").replace(/\s*$/,"");
}

Javascript String trim()

String.prototype.trim = function ()
{
 return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}

"[" + "         1234    ".trim() + "]"

Javascript String trim()

Delicious = {/*from w w  w.j  a va 2  s  . com*/
 getTimeStamp: function()
 {
  var d = new Date();
  return Math.floor(d.getTime()/1000);
 }
};


String.prototype.trim = function() 
{
 var str = this.replace(/^\s\s*/, ''),
  ws = /\s/,
  i = str.length;
 while (ws.test(str.charAt(--i)));
 return str.slice(0, i + 1);
}
String.prototype.localize = function()
{
 return $L(this);
}

Javascript String trim()

String.prototype.trim = function(){
 return this.replace(/^\s+/,"").replace(/\s+$/,"");
}
var str="  aaaa    bbbb   ";
str=str.trim();// w  w  w .  j a  v a 2  s  .  com
console.log(str);

Javascript String trim()

String.prototype.trim = function() {
 return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");
}

Javascript String trim()

String.prototype.trim = function() {
 return this.replace(/^\s+|\s+$/g, "");
};
function pattern(n){
 var output="";
 for(var i=1;i<n+1;i++){
  output += 1 + '*'.repeat(i-1) + ((i>1) ? i + '\n': '\n')
 }
 output = output.trim();//w  ww  .j  a v a2 s .c  o m
 return output;
}

Javascript String trim()

String.prototype.trim = function()
{
  return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

Javascript String trim()

String.prototype.trim = String.prototype.trim || function () {
 var str = this.replace(/^\s\s*/, ''),
  i = str.length;/*from  w w  w  . j  av a2  s  .  c o m*/

 for (let rgxp = /\s/; rgxp.test(str.charAt(--i));) {}
 return str.substring(0, i + 1);
};

Javascript String trim()

function realLength(str)
{
  return str.replace(/[^\x00-\xff]/g,"**").length;
}
String.prototype.trim = function(){return this.replace(/^\s*|\s*$/g,"");}
function trimForm(form){
  for(var i=0;i<form.length;i++){
   if(form[i].type =="text"){
    form[i].value = form[i].value.trim();
    //from w w  w  .ja  v  a  2s . co  m
   }
  } 
}

Javascript String trim()

/**//from   w  ww  .j  a v  a 2 s  .  c o m
 * Created by JetBrains WebStorm.
 * User: mike
 * Date: 12/01/13
 * Time: 21:03
 * To change this template use File | Settings | File Templates.
 */

String.prototype.trim = function () {
    return this.replace(/^\s+/, "").replace(/\s+$/, "");
};

Javascript String trim()

/**//from w w  w . j ava2s .  c  o  m
 * Trims the whitespace around the text.
 *
 * @return {String} The trimmed string.
 */

String.prototype.trim = function()
{
 return this.replace(/^[\s]+|[\s]+$/g, "");
};

Javascript String trim()

/*/*from  w  ww .j  av  a  2  s  .  c o  m*/
*Trim 
*removes whitespace on start and end of string
*/
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
};

Javascript String Trim()

String.prototype.Trim = function() { 
 return this.replace(/(^\s*)|(\s*$)/g,""); 
}

Javascript String trim()

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
};

Javascript String trim()

/**/*from w  w w  .  ja  va  2s. co  m*/
 * @returns a new String without white spaces (space, tab) at beginning and at end.
 */
String.prototype.trim = function() {
 return this.replace(/^\s+|\s+$/g, "");
};

Javascript String trim()

String.prototype.trim = function(){
 var str = this.toString();
 var leng = str.length;
 var index = str.indexOf(" ");
 if(index == 0){/*from w  w  w . j  a  v a  2s. co m*/
  str = str.substr(index + 1,leng - 1);
      
  if(str.indexOf(" ") == 0){
   str = trim(str);
  }
 }
 while(str.lastIndexOf(" ") != -1){
  str = str.substr(0,str.length - 1);
 }
     
 return str;
}

Javascript String trim()

// stolen from http://www.somacon.com/p355.php
String.prototype.trim = function() {
 return this.replace(/^\s+|\s+$/g,"");
}

Javascript String trim()

//Trim Strings//w w  w . ja v  a2 s  . co  m

String.prototype.trim = function(){
 return this.replace(/^\s+|\s+%/g/"");
}

Javascript String trim()

String.prototype.trim = function() {
 
 var start = 0, end = this.length - 1;
 
 while (start <= end && this.charAt(start) == " ") {
  start++;//from  w  w  w  .  j  a va 2s . c om
 }
 
 while (start <= end && this.charAt(end) == " ") {
  end--;
 }
 return this.substring(start, end + 1);
};

Javascript String trim()

function stringFilter(s) { 
 var pattern = new RegExp("[`%@#$^&=|\\[\\]<>/@#? ?? ??& ?? ??|]") 
 var rs = ""; 
 for (var i = 0; i < s.length; i++) { 
  rs = rs+s.substr(i, 1).replace(pattern, ''); 
 }
 return rs; //from  www .  ja  v a2 s .c o  m
} 
String.prototype.trim = function() {
  return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

Javascript String trim()

String.prototype.trim = function()
{return this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")}

var myString = "   hello world    ";
var myTrimmedString = myString.trim();

alert("'" + myString + "'" + "\n" + "'" + myTrimmedString + "'");

Javascript String trim()

// trim whitespaces left and right
String.prototype.trim = function() {
  return this.replace(/^\s*|\s*$/g,'');
}

Javascript String trim()

String.prototype.trim = String.prototype.trim || function () {

 return this.replace( /^\s+|\s+$/g, '' );

};

Javascript String trim()

// Extend the String prototype by a trim function, that returns the string with leading or trailing whitespaces removed.

// Examples can be found in the test fixture.

// PS: Of course, the original trim function was removed before ;)

String.prototype.trim = function () {
  return this.replace(/^\s+|\s+$/g, "");
}

Javascript String trim()

/**/*from www  .  ja  v  a  2s . co m*/
@Name: String.prototype.trim
@Description: trims whitespace from both left and right side of a string
@Return: String The original string with whitespace removed from left and right side
@Example:
var str = '    hello world       ';

var newString = str.trim();
//newString = 'hello world'
*/
String.prototype.trim = function() {
 return this.replace(/(^\s+|\s+$)/g, '');
};

Javascript String trim()

String.prototype.trim = function() {
    var reExtraSpace = /^\s*(.*?)\s+$/;
    return this.replace(reExtraSpace, "$1")
}


function ltrim(s){ return s.replace( /^(\s*|?*)/, ""); } 


function rtrim(s){ return s.replace( /(\s*|?*)$/, ""); }

Javascript String trim()

/*eslint-env shared-node-browser, mocha */
'use strict';//  ww w . j  a va  2  s  .c o  m

/**
 * trim string
 *
 * prototype String trim method
 */

module.exports = function(string) {
  return String.prototype.trim.call(string);
}

String.prototype.trim = String.prototype.trim || function() {
  return this.replace(/(^\s*)|(\s*$)/g, "")
};

Javascript String trim()

/**//from w  ww . ja va2s. c  o  m
 * String.prototype.trim Polyfill
 */

String.prototype.trim = (function() {

        var trimRegex = /(^\s+|\s+$)/g;

        return function() {
                return this.replace(trimRegex, '');
        };

}());

/* End of file trim.js */

Javascript String trim()

String.prototype.trim = function() {
  return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

function validPhoneNumber(phoneNumber){
  //TODO: Return whether phoneNumber is in the proper form
  return phoneNumber.match(/^\(\d{3}\)\s\d{3}-\d{4}$/);
}

console.log('    kia    '.trim());

Javascript String trim()

/* base on jquery.js and jquery-utils.js */
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

Javascript String trim()

String.prototype.trim = function() {
 return this.replace(/(^\s*)|(\s*$)|($\s*)/g, "");
};

Javascript String trim()

// The purpose of this file is to have a place to store javascript prototype functions that can be used throughout the project.

// This function removes all spaces at the beginning and end of a string
String.prototype.trim = function() {
 a = this.replace(/^\s+/, '');
 return a.replace(/\s+$/, '');
};

Javascript String trim()

String.prototype.trim = function() {
 var re = /^\s+|\s+$/g;
 return this.replace(re, "");
}

Javascript String trim()

String.prototype.trim = function() {
  return this.replace(/^[\s\u3000]+|[\s\u3000]+$/g, '');
};

Javascript String trim()

String.prototype.trim = function() {
 return this.replace(/(^\s*)|(\s*$)/g,'');
};

Javascript String trim()

String.prototype.trim = function() { // not inflector, just helper for its libraries
 return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

Javascript String trim()

String.prototype.trim = function () {
 var reExtraSpace = /^\s+(.*?)\s+$/;
 return this.replace(reExtraSpace, "$1");
};
var script = document.getElementsByTagName("script");
var template = {};
for(var i = 0; i < script.length; i++){
 if(script[i].getAttribute("type") == "template"
  && script[i].id)/*from   w ww .j a v  a 2  s  .c o  m*/
 {
  template[script[i].id] = script[i].innerHTML;   
  template[script[i].id].trim();   
 }
}
parent.postMessage(template, "*");

Javascript String trim()

String.prototype.trim = String.prototype.trim || function () {
 const//from   w  ww .  ja  va 2  s .  c  o m
  str = this.replace(/^\s\s*/, '');

 let
  i = str.length;

 for (let rgxp = /\s/; rgxp.test(str.charAt(--i));) {

 }

 return str.substring(0, i + 1);
};

Javascript String trim()

String.prototype.trim = function(){ 
 return this.rTrim(this.lTrim());
}

Javascript String trim()

String.prototype.trim = function () {
    var re = /^\s+|\s+$/g;
    return function () { return this.replace(re, ""); };
}();/*from w  w  w .  j a  v a  2 s.c  om*/

Javascript String trim()

// trimmming/*from w  ww.  j  av a 2s  . com*/
String.prototype.trim = function() {
  s = this.replace( /^\s+/g, '');
  return s.replace( /\s+$/g, '');
}

Javascript String trim()

/**// ww w.j a v  a  2  s  . c o m
 * 018_trim_a_string.js
 * http://www.codewars.com/kata/trim-a-string/train/javascript
 *
 * Sjaak van den Berg
 * https://www.twitter.com/svdb
 */

/**
 * Extend the String prototype by a `trim` function, that returns the string
 * with leading or trailing whitespaces removed.
 */

String.prototype.trim = function() {
  return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

// Alternative

String.prototype.trim2 = function() {
  return this.replace(/^\s+|\s+$/g, '');
};

'foo     '.trim(); // 'foo'
'     foo'.trim(); // 'foo'
'  foo   '.trim(); // 'foo'
'foo  bar'.trim(); // 'foo  bar'
'        '.trim(); // ''

Javascript String trim()

String.prototype.trim = String.prototype.trim || function () {
 if( !this ) {/*  w ww  .  jav  a2 s . c o  m*/
  return this;
 }
 return this.replace(/^\s+|\s+$/g, "");
};

Javascript String trim()

/*//from   ww  w .  java 2s .  co  m
* JQuery util functions
* 
* Author: Faraz Masood Khan faraz@fanaticlab.com
* 
* Copyright (c) 2013 FanaticLab  
*/

String.prototype.trim = String.prototype.trim || function () {
    return this.replace(/^\s+|\s+$/g, "");
};

Javascript String trim()

/**********************************************************
 * Framework/*from  www.  j  a v a2s .c o m*/
 **********************************************************/
 
var frw = {};
module.exports = frw;

frw.Template = require("./frw.Template");

/**
 * Remove blank space on right and left side of the string
 */
if (!String.prototype.trim) {
 String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, "");
 };
}

/**
 * supplant is used by the template engine
 */
String.prototype.supplant = function (o) {
 return this.replace(/{([^{}]*)}/g,
  function (a, b) {
   var r = o[b];
   return (r !== undefined) ? r : a;
  }
 );
};

Javascript String trim()

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
};

function getCookie(name) {
 var cookieValue = null;
 if (document.cookie && document.cookie != '') {
  var cookies = document.cookie.split(';');
  for (var i = 0; i < cookies.length; i++) {
   var cookie = cookies[i].trim();
   // Does this cookie string begin with the name we want?
   if (cookie.substring(0, name.length + 1) == (name + '=')) {
    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
    break;/*  ww w . j  a v a  2s.  c  o m*/
   }
  }
 }
 return cookieValue;
}

Javascript String trim()

function recursivePrint(start, end, acc) {
 if (start > end) {
  return acc;//from w ww.jav  a 2  s . c  om
 }
 return recursivePrint(start + 1, end, acc + start);
}

function arraySum(arr) {
 return arr.reduce(function(prev, next) {
  return prev + next;
 });
}

function arrayMax(arr) {
 return arr.reduce(function(prev, next) {
  return (next > prev) ? next : prev;
 });
}

function arrayMin(arr) {
 return arr.reduce(function(prev, next) {
  return next < prev ? next : prev;
 });
}

String.prototype.trim = function() {
 return this.replace(/\s{1,}$|^\s{1,}/g, '');
}

export { recursivePrint, arraySum, arrayMax, arrayMin };

Javascript String trim()

String.prototype.trim = function() {
    return this == null ? "" : (this + "").replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
};

Javascript String trim()

function validateEmail(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}
function CancelEnter() {
    if (event.keyCode == 13) {
        return false;
    }/* w w w .j  av  a  2  s .c  o m*/
    else {
        return true;
    }
}
function concatObject(obj) {
    str = '';
    for (prop in obj) {
        str += prop + " value :" + obj[prop] + "\n";
    }
    return (str);
}
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
};

Javascript String trim()

'use strict';//from   w  w w .j  a va 2 s .co m

/*!
 * Snakeskin
 * https://github.com/SnakeskinTpl/Snakeskin
 *
 * Released under the MIT license
 * https://github.com/SnakeskinTpl/Snakeskin/blob/master/LICENSE
 */

Array.isArray = Array.isArray || function (obj) {
 return {}.call(obj) === '[object Array]';
};

String.prototype.trim = String.prototype.trim || function () {
 const
  str = this.replace(/^\s\s*/, '');

 let
  i = str.length;

 for (let rgxp = /\s/; rgxp.test(str.charAt(--i));) {
  // Do nothing
 }

 return str.substring(0, i + 1);
};

Javascript String trim()

String.prototype.trim = function() {
 return this.replace(/^\s*|\s*$/g, "");
};

Javascript String trim()

String.prototype.trim = function() {
  var result = this;

  while (result.charAt(0) === ' ') {
    result = result.substr(1);//from w  ww . j  av a  2  s  . com
  }

  while (result.substr(-1) === ' ') {
    result = result.substr(0, result.length - 1);
  }

  return result.toString();
}

Javascript String trim()

/**/*from w  w w .  j a va 2s.c  om*/
 * Created with IntelliJ IDEA.
 * User: bigdog
 * Date: 5/29/13
 * Time: 7:22 AM
 */

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

Javascript String trim()

if( !String.prototype.trim ) {
 String.prototype.trim = function () {
  return this.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '' );
 };//  w ww. j a v a2 s  .  c o  m
}

Javascript String trim()

// --- Prototypes

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
};

Javascript String trim()

'use strict';//  w w  w .  ja va  2  s  .  co  m
const showapi = require('../common/showapi')

String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g, "");
}

Javascript String trim()

String.prototype.trim = function () {
 return this.replace(/^\s+|\s+$/g, "");
};

Javascript String Trim()

String.prototype.Trim = function(){ return Trim(this);}
String.prototype.LTrim = function(){return LTrim(this);}
String.prototype.RTrim = function(){return RTrim(this);}

function LTrim(str)
{
    var i;//ww w .  j  av a 2s  .co m
    for(i=0;i<str.length;i++)
    {
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
    }
    str=str.substring(i,str.length);
    return str;
}
function RTrim(str)
{
    var i;
    for(i=str.length-1;i>=0;i--)
    {
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
    }
    str=str.substring(0,i+1);
    return str;
}
function Trim(str)
{
    return LTrim(RTrim(str));
}

Javascript String trim()

String.prototype.trim = function() {
    'use strict';
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
};

Javascript String trim()

/*//from   w  w w .j  ava 2  s .c om
* Licensed Materials - Property of IBM
* Restricted Materials of IBM
* 5724-U18
* (C) COPYRIGHT IBM CORP. 2006,2009 All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with
* IBM Corp.
*
*/
String.prototype.trim = function()
{
 return this.replace(/^\s+|\s+$/g, '');
};

String.prototype.endsWith = function(str)
{
 return (this.match(str+"$")==str);
};

String.prototype.startsWith = function(str)
{
 return (this.match("^"+str)==str);
};

String.prototype.regionMatches = function(strStart, str2, str2Start, lth)
{
 if(this.substr(strStart,lth) == str2.substr(str2Start,lth))
 {
  return true;
 }
 else
 {
  return false;
 }
};

Javascript String trim()

/**/*from   w ww.j  ava2s.  c o  m*/
 * Trim the results from spaces from the beginning and end
 * @return {string} the trimmed string.
 */
String.prototype.trim = function () {
    return this.replace(/^\s*/, '').replace(/\s*$/, '');
};

Javascript String Trim()

String.prototype.Trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
};



PreviousNext

Related