2017-01-17 4 views
0

일부 문자와 기호가 포함 된 문자열이 있는데 그 중 일부는 ASCII 코드가 있고 그 중 일부는 기호를 포함하지 않습니다.ASCII 기호가 아닌 기호가 인쇄되지 않습니다.

à – string çöntäining nön äsçii çhäräçtérs couldn’t 
A string containing non ascii characters couldnt 

나는 또한 "--"원하는 제공된 문자열 값에서 "'"나는 문자가 아닌 문자

String strValue = "Ã – string çöntäining nön äsçii çhäräçtérs couldn’t"; 
     String str = Normalizer.normalize(strValue, Normalizer.Form.NFD); 
     System.out.println(str); 
     System.out.println(str.replaceAll("[^\\p{ASCII}]","")); 

출력은 변환 할 수 있어요있는 아래의 코드를 시도했습니다. 내가 정상화하지 않으면

은 그냥 ""로 원하는 문자를 대체하지 않습니다

? ? string ??nt?ining n?n ?s?ii ?h?r??t?rs couldn?t 
+0

두 문자는 ('-'와' '') 아스키 .. –

+0

예 내가 알고 **되지 않습니다 ** 그러나 "이"로 교체하지 않는 –

+0

얻을 수있는 방법은 무엇입니까? –

답변

2

내 문자열로 변환 :

String strValue = "Ã – string çöntäining nön äsçii çhäräçtérs couldn’t"; 
String str = Normalizer.normalize(strValue, Normalizer.Form.NFD); 
System.out.println(str); 
System.out.println(str.replaceAll("[^\\p{ASCII}–’]","")); // ie. replace not (ascii or – or ’) 

출력 :

à – string çöntäining nön äsçii çhäräçtérs couldn’t 
A – string containing non ascii characters couldn’t 

데모 : https://ideone.com/6zpYao

+0

오, 그래서 내 바보가 정규식에 추가 할 수있다. –

0

해당 문자를 구체적으로 바꾸려면 먼저 바꿀 수 있습니다.

str = str.replaceAll("’", "'"); 
str = str.replaceAll("–", "--"); 
str = str.replaceAll("[^\\p{ASCII}–’]","");