본문 바로가기

아는 만큼 보인다/Tip

문자열 속 일부 유니코드 치환


// 문자열 속 일부 유니코드 치환

public void replaceUnicodeNotation(String input) {

while( true ) {

Matcher m = Pattern.compile("\\\\u([\\da-fA-F]{4})").matcher(input);

if(!m.find()) break;


char ch = (char) Integer.parseInt(m.group(1), 16);

String a = String.valueOf( ch );

input = m.replaceFirst( Matcher.quoteReplacement(a) );

}

return input;

}

'아는 만큼 보인다 > Tip' 카테고리의 다른 글