2017-12-09 1 views
0

내가 직접 유니 코드를 입력하면 그림 이모티콘을보고 같은 방법으로 String로 변환 할 수 있습니다 :stringbuffer를 문자열로 변환했지만 문자열을 유니 코드 int로 변환하는 방법은 무엇입니까?

int intUnicode = 0x1F601; 

public String getEmojiByUnicode(int unicode) { 
    return new String(Character.toChars(unicode)); 
} 

하지만 난 그냥 유니 코드 값이 String 같은 경우 변환하는 방법 주위에 내 머리를 정리 할 수 ​​없습니다

String strUnicode = "0xf601"; 

직접 작성한 것처럼 Integer으로 변환하는 방법. Integer.parseInt(strUnicode) 컴파일러를 사용할 때마다 오류가 발생합니다.

InputStream is = assetManager.open("emoji_unicode.txt"); 
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
if (is != null){ 
    try { 
     while ((data = reader.readLine()) != null){ 
      sbuffer.append(data + "\n"); 
      String j = sbuffer.toString().trim(); 
      int k = Integer.parseInt(j,16); 
      String l = getEmojiByUnicode(k); 
      emoArray.add(l); 
     } 
     btn.setText(emoArray.get(5)); 
     is.close(); 
    }catch (IOException e){ 
     e.printStackTrace(); 
    } 
} 

매우 어렵지는 않지만 매우 가깝지만 여전히 나에게 다가 가지 않습니다. 어떤 도움을 주시면 감사하겠습니다. 당신은 진수 문자열 구문 분석을 시도하고

+0

귀하의 유니 코드 문자열이 첫 번째 예에서 생성 된 것과 동일하지 않습니다. [UTF-16] (https://en.wikipedia.org/wiki/UTF-16) 인코딩을보고 [작업중인 범위]의 코드 포인트에 어떻게 적용되는지 확인해야합니다 (https : //en.wikipedia.org/wiki/UTF-16#U+10000_to_U+10FFFF). 컴파일러가 제공하는 문자열이 유효한 UTF-16이 아니기 때문에 컴파일러가 불평을합니다. – Jules

+0

[16 진수 문자열을 정수로 구문 분석하면 NumberFormatException이 throw됩니다.] 가능한 복제본 (https://stackoverflow.com/questions/11377944/parsing-a-hexadecimal-string-to-an-integer-throws-a-numberformatexception) –

답변

관련 문제