Created
March 2, 2016 01:52
-
-
Save arahansa/e29eb5fcabc6d503a0e3 to your computer and use it in GitHub Desktop.
한글 3바이트 처리하는 자바처리
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void koreanCheck2() throws Exception { | |
String msg ="일이>삼사오육칠팔구십"; | |
byte[] test = msg.getBytes("UTF-8"); | |
System.out.println("총길이 :"+test.length); | |
int lastPosition = 0; | |
for(int i=0;i<20;i++){ | |
int iChar = (int) test[i]; | |
if ((iChar > 127) || (iChar < 0)) { | |
// 한글의 경우(2byte 통과처리) | |
// 한글은 2Byte이기 때문에 다음 글자는 볼것도 없이 스킵한다 | |
i+=2; // 한개 더 해서 3byte | |
} | |
if(i<20) | |
lastPosition=i; | |
System.out.println("현재 라스트 포지션 :"+ lastPosition); | |
} | |
lastPosition++; | |
System.out.println("라스트 포지션 :"+lastPosition); | |
System.out.println("서브스트링 :"+new String(test, 0, lastPosition)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment