Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: capitalize each word from string in react 
Javascript :: in vs of javascript 
Javascript :: javascript check table not empty 
Javascript :: js sum digits 
Javascript :: typeof in js 
Javascript :: convert % to px javascript 
Javascript :: paragraph to single line in javascript 
Javascript :: react redux thunk 
Javascript :: how to use json stringify in javascript 
Javascript :: $.get jquery return value 
Javascript :: react native map 
Javascript :: javascript for...of with Strings 
Javascript :: end session express 
Javascript :: js convert obj to array 
Javascript :: how make calender in bootstrap 
Javascript :: react recoil 
Javascript :: append javascript example 
Javascript :: set id to div element in Javascript 
Javascript :: ejs render 
Javascript :: clone array 
Javascript :: javascript merge two array with spread operator 
Javascript :: fingerprint js 
Javascript :: jquery autocomplete bootstrap modal 
Javascript :: jquery slider move event 
Javascript :: jquery a tag click 
Javascript :: round 2 decimales js 
Javascript :: split and join in javascript 
Javascript :: mongodb add 1 to field 
Javascript :: reactjs change fill color .svg 
Javascript :: Country API JavaScript Code 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =