좋은 자료가 있어서 올립니다.
초성 검색에 사용하면 유용할 것 같네요.
- (NSString *)GetUTF8String:(NSString *)hanggulString {
NSArray *chosung = [[NSArray alloc]initWithObjects:@"ㄱ",@"ㄲ",@"ㄴ",@"ㄷ",@"ㄸ",@"ㄹ",@"ㅁ",@"ㅂ",@"ㅃ",@"ㅅ",@"ㅆ",@"ㅇ",@"ㅈ",@"ㅉ",@"ㅊ",@"ㅋ",@"ㅌ",@"ㅍ",@"ㅎ",nil];
NSArray *jungsung = [[NSArray alloc]initWithObjects:@"ㅏ",@"ㅐ",@"ㅑ",@"ㅒ",@"ㅓ",@"ㅔ",@"ㅕ",@"ㅖ",@"ㅗ",@"ㅘ",@"ㅙ",@"ㅚ",@"ㅛ",@"ㅜ",@"ㅝ",@"ㅞ",@"ㅟ",@"ㅠ",@"ㅡ",@"ㅢ",@"ㅣ",nil];
NSArray *jongsung = [[NSArray alloc]initWithObjects:@"",@"ㄱ",@"ㄲ",@"ㄳ",@"ㄴ",@"ㄵ",@"ㄶ",@"ㄷ",@"ㄹ",@"ㄺ",@"ㄻ",@"ㄼ",@"ㄽ",@"ㄾ",@"ㄿ",@"ㅀ",@"ㅁ",@"ㅂ",@"ㅄ",@"ㅅ",@"ㅆ",@"ㅇ",@"ㅈ",@"ㅊ",@"ㅋ",@" ㅌ",@"ㅍ",@"ㅎ",nil];
NSString *textResult = @"";
for (int i=0;i<[hanggulString length];i++) {
NSInteger code = [hanggulString characterAtIndex:i];
if (code >= 44032 && code <= 55203) {
NSInteger uniCode = code - 44032;
NSInteger chosungIndex = uniCode / 21 / 28;
NSInteger jungsungIndex = uniCode % (21 * 28) / 28;
NSInteger jongsungIndex = uniCode % 28;
textResult = [NSString stringWithFormat:@"%@%@%@%@", textResult, [chosungobjectAtIndex:chosungIndex], [jungsung objectAtIndex:jungsungIndex], [jongsung objectAtIndex:jongsungIndex]];
}
}
return textResult;
}
- (void)loadView {
[super loadView];
NSLog( @"%@", [self GetUTF8String:@"투덜이"]);
}