Skip to content

Instantly share code, notes, and snippets.

@ParkSangGwon
Created August 4, 2016 09:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ParkSangGwon/c3fc35dd1072255b72b68920e7aeaae6 to your computer and use it in GitHub Desktop.
Save ParkSangGwon/c3fc35dd1072255b72b68920e7aeaae6 to your computer and use it in GitHub Desktop.
안드로이드,JAVA에서 단어에 따라서 '을/를', '이/가','은/는' 구분하기
public class KoreanUtil {
public static final String getComleteWordByJongsung(String name, String firstValue, String secondValue) {
char lastName = name.charAt(name.length() - 1);
// 한글의 제일 처음과 끝의 범위밖일 경우는 오류
if (lastName < 0xAC00 || lastName > 0xD7A3) {
return name;
}
String seletedValue = (lastName - 0xAC00) % 28 > 0 ? firstValue : secondValue;
return name+seletedValue;
}
}
@ParkSangGwon
Copy link
Author

사용법
KoreanUtil.getComleteWordByJongsung("박상권","을","를")

@b1uec0in
Copy link

b1uec0in commented May 24, 2017

이 글을 보고 아이디어를 얻어 String.format 처럼 편리하게 쓸 수 있도록 만들어 봤습니다.
https://github.com/b1uec0in/AndroidJosaFormatter

블로그의 댓글(http://gun0912.tistory.com/65 )을 보고 영어나 숫자도 되도록 하긴 했는데, 정확한 규칙을 잘 모르겠네요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment