Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String.prototype.trim=function(){return this.replace(/^s+|s+$/g, '');};
- String.prototype.ltrim=function(){return this.replace(/^s+/,'');};
- String.prototype.rtrim=function(){return this.replace(/s+$/,'');};
- String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|n)s+|s+(?:$|n))/g,'').replace(/s+/g,' ');};
- if (!String.prototype.trim) {
- //code for trim
- }
- $.trim(' your string ');
- if(!String.prototype.trim){
- String.prototype.trim = function(){
- return this.replace(/^s+|s+$/g,'');
- };
- }
- String.prototype.trim = function() {
- return this.replace(/^s+|s+$/g, "");
- };
- " foo bar ".trim(); // "foo bar"
- function trim(str) {
- return str.replace(/^s+|s+$/g,"");
- }
- document.getElementById("id").value.trim();
- /**
- * Trim string. Actually trims all control characters.
- * Ignores fancy Unicode spaces. Forces to string.
- */
- function trim(str) {
- str = str.toString();
- var begin = 0;
- var end = str.length - 1;
- while (begin <= end && str.charCodeAt(begin) < 33) { ++begin; }
- while (end > begin && str.charCodeAt(end) < 33) { --end; }
- return str.substr(begin, end - begin + 1);
- }
- var orig = " foo ";
- console.log( orig.trim() );//foo
- ' Hello '.trim() //-> 'Hello'
- ' Hello '.trimLeft() //-> 'Hello '
- ' Hello '.trimRight() //-> ' Hello'
- if (!''.trimLeft) {
- String.prototype.trimLeft = function() {
- return this.replace(/^s+/,'');
- };
- String.prototype.trimRight = function() {
- return this.replace(/s+$/,'');
- };
- if (!''.trim) {
- String.prototype.trim = function() {
- return this.replace(/^s+|s+$/g, '');
- };
- }
- }
- String.prototype.trim = String.prototype.trim || function () {
- return this.replace(/^s+|s+$/g, "");
- };
- String.prototype.trimLeft = String.prototype.trimLeft || function () {
- return this.replace(/^s+/, "");
- };
- String.prototype.trimRight = String.prototype.trimRight || function () {
- return this.replace(/s+$/, "");
- };
- String.prototype.trimFull = String.prototype.trimFull || function () {
- return this.replace(/(?:(?:^|n)s+|s+(?:$|n))/g, "").replace(/s+/g, " ");
- };
- var trim = (function() {
- // if a reference is a `String`.
- function isString(value){
- return typeof value == 'string';
- }
- // native trim is way faster: http://jsperf.com/angular-trim-test
- // but IE doesn't have it... :-(
- // TODO: we should move this into IE/ES5 polyfill
- if (!String.prototype.trim) {
- return function(value) {
- return isString(value) ?
- value.replace(/^s*/, '').replace(/s*$/, '') : value;
- };
- }
- return function(value) {
- return isString(value) ? value.trim() : value;
- };
- })();
- String.prototype.trim = String.prototype.trim || function(){ return jQuery.trim(this); };
- var str = new String('my string');
- str= str.trim();
- var str = " Hello World! ";
- alert(str.trim());
- var some_string_with_extra_spaces=" goes here "
- console.log(some_string_with_extra_spaces.match(/S.*S|S/)[0])
- console.log(some_string_with_extra_spaces.match(/S[sS]*S|S/)[0])
- console.log(some_string_with_extra_spaces.match(/^s*(.*?)s*$/)[1])
- var trim: (input: string) => string = String.prototype.trim
- ? ((input: string) : string => {
- return (input || "").trim();
- })
- : ((input: string) : string => {
- return (input || "").replace(/^s+|s+$/g,"");
- })
- function trim(str)
- {
- var startpatt = /^s/;
- var endpatt = /s$/;
- while(str.search(startpatt) == 0)
- str = str.substring(1, str.length);
- while(str.search(endpatt) == str.length-1)
- str = str.substring(0, str.length-1);
- return str;
- }
- form.elements[i].value = trim(form.elements[i].value);
- var illmatch= /^(s*)(?:.*?)(s*)$/
- function strip(me){
- var match= illmatch.exec(me)
- if(match && (match[1].length || match[2].length)){
- me= me.substring(match[1].length, p.length-match[2].length)
- }
- return me
- }
- if(match && (match[1].length || match[3].length)){
- me= match[2]
- }
- function trim(str){
- return str.split(' ').join();
- }
- function trim(text) {
- return (text == null) ? '' : ''.trim.call(text);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement