Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove ↵ character from JS string

I have a string like

↵my name is Pankaj↵

I want to remove the character from the string.

"↵select * from eici limit 10".replace("↵", "") 

Works fine. But I want to know if there is any other way to remove these kind of unnecessary characters.

like image 419
ipankaj Avatar asked Mar 17 '15 11:03

ipankaj


1 Answers

Instead of using the literal character, you can use the codepoint.

Instead of "↵" you can use "\u21b5".

To find the code, use '<character>'.charCodeAt(0).toString(16), and then use like \u<number>.

Now, you can use it like this:

string.split("\u21b5").join(''); //split+join

string.replace(/\u21b5/g,'');  //RegExp with unicode point
like image 54
Ismael Miguel Avatar answered Sep 30 '22 06:09

Ismael Miguel