Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

.trim() method

trim is a method that removeds whitespaces  from both ends of a string and returns a new string, without modifying the original string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.)
Comment

trim string

const arr = [' a ', ' b ', ' c '];

const results = arr.map(element => {
  return element.trim();
});

console.log(results); 
//result
//['a', 'b', 'c']

//trim single string
var str="		abc c a				"
str.trim()

console.log(str);
//result
//abc c a
Comment

trim function

/* Remove leading whitespaces */
char *ltrim(char *const s)
{
        size_t len;
        char *cur;

        if(s && *s) {
                len = strlen(s);
                cur = s;

                while(*cur && isspace(*cur))
                        ++cur, --len;

                if(s != cur)
                        memmove(s, cur, len + 1);

        }

        return s;
}

/* Remove trailing whitespaces */
char *rtrim(char *const s)
{
        size_t len;
        char *cur;

        if(s && *s) {
                len = strlen(s);
                cur = s + len - 1;

                while(cur != s && isspace(*cur))
                        --cur, --len;

                cur[isspace(*cur) ? 0 : 1] = '';
        }

        return s;
}

/* Remove leading and trailing whitespaces */
char *trim(char *const s)
{
        rtrim(s);  // order matters
        ltrim(s);

        return s;
}
Comment

A string trim function

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

PREVIOUS NEXT
Code Example
Javascript :: request module nodejs 
Javascript :: JavaScript Debug usage Example 
Javascript :: classlist toggle 
Javascript :: drag n drop file upload react 
Javascript :: javascript meme 
Javascript :: return data with ajax 
Javascript :: setimmediate javascript 
Javascript :: !! javascript 
Javascript :: js oop 
Javascript :: radio button in reactive forms angular material 
Javascript :: dynamic key in javascript object 
Javascript :: new function javascript 
Javascript :: reactjs events list 
Javascript :: best computer language 
Javascript :: get x y z position of mouse javascript 
Javascript :: how to upload document cloddinary 
Javascript :: identifier in js 
Javascript :: react native tdd emzyme 
Javascript :: get table schema with knex 
Javascript :: using the for of loop in pure javascript to populate data into HTML 
Javascript :: subdomain react app 
Javascript :: exemplo simples de socket com node 
Javascript :: document.elementFromPoint 
Javascript :: jquery unobtrusive validation asp.net core 
Javascript :: convert jquery code to javascript online 
Javascript :: event.target.value inside vf page 
Javascript :: what is es11 
Javascript :: quasar composition api $q 
Javascript :: what does god expect of me 
Javascript :: moment add days non destructive 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =