Reputation: 877
how can I remove whitespace and carriage return from a String. I got something like this..
exampleName↵
but need just the text and not the symbol at the end.
Upvotes: 0
Views: 2637
Reputation: 5682
What about trim method?
var str = " Hello World! ";
alert(str.trim());
Edit based on the comments: I am not sure what character '↵' is... trim()
is supposed to remove white-space chars including new-line and carriage-return... so what about the following
var a="exampleName↵";
a.replace(/↵/g, "")
alert(a)
Fiddle: https://jsfiddle.net/dbth6tx8/4/
Upvotes: 5
Reputation: 4653
try this
var s = ' Your string with newline or/and carriage return ';
s = s.replace(/(?:\r\n|\n|\r)/g, '').replace(/^\s+|\s+$|\s+(?=\s)/g, '');
Upvotes: 1
Reputation: 536
var a="exampleName↵";
var mystring = a.replace(/[^\w\s]/gi, '');
alert(mystring);
Upvotes: 0