Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove non-ascii character in string

var str="INFO] :谷���新道, ひば���ヶ丘2丁���, ひばりヶ���, 東久留米市 (Higashikurume)"; 

and i need to remove all non-ascii character from string,

means str only contain "INFO] (Higashikurume)";

like image 475
Dev Avatar asked Dec 31 '13 10:12

Dev


People also ask

How do I remove non ASCII characters from a string in Python?

In python, to remove non-ASCII characters in python, we need to use string. encode() with encoding as ASCII and error as ignore, to returns a string without ASCII character use string. decode().

What is \\ x00 -\\ x7F?

US-ASCII is a character set (and an encoding) with some notable features: Values are between 0–127 (x00–x7F) ASCII code-point 32 (decimal) represents a SPACE. ASCII code-point 65 represents the uppercase letter A.

How do I remove non-printable characters from a string?

replaceAll("\\p{Cntrl}", "?"); The following will replace all ASCII non-printable characters (shorthand for [\p{Graph}\x20] ), including accented characters: my_string.


1 Answers

ASCII is in range of 0 to 127, so:

str.replace(/[^\x00-\x7F]/g, ""); 
like image 51
Zaffy Avatar answered Sep 26 '22 05:09

Zaffy