- 오브젝티브C Linear Hangul 함수
- Objective-C 한글 초성, 중성, 종성 분리
- Objective-C 한글 풀어쓰기 함수
1 소스 코드[ | ]
Objective-C
Copy
- (NSString *)LinearHangul:(NSString *)str {
NSArray *cho = [[NSArray alloc] initWithObjects:@"ㄱ",@"ㄲ",@"ㄴ",@"ㄷ",@"ㄸ",@"ㄹ",@"ㅁ",@"ㅂ",@"ㅃ",@"ㅅ",@"ㅆ",@"ㅇ",@"ㅈ",@"ㅉ",@"ㅊ",@"ㅋ",@"ㅌ",@"ㅍ",@"ㅎ",nil];
NSArray *jung = [[NSArray alloc] initWithObjects:@"ㅏ",@"ㅐ",@"ㅑ",@"ㅒ",@"ㅓ",@"ㅔ",@"ㅕ",@"ㅖ",@"ㅗ",@"ㅘ",@"ㅙ",@"ㅚ",@"ㅛ",@"ㅜ",@"ㅝ",@"ㅞ",@"ㅟ",@"ㅠ",@"ㅡ",@"ㅢ",@"ㅣ",nil];
NSArray *jong = [[NSArray alloc] initWithObjects:@"",@"ㄱ",@"ㄲ",@"ㄳ",@"ㄴ",@"ㄵ",@"ㄶ",@"ㄷ",@"ㄹ",@"ㄺ",@"ㄻ",@"ㄼ",@"ㄽ",@"ㄾ",@"ㄿ",@"ㅀ",@"ㅁ",@"ㅂ",@"ㅄ",@"ㅅ",@"ㅆ",@"ㅇ",@"ㅈ",@"ㅊ",@"ㅋ",@" ㅌ",@"ㅍ",@"ㅎ",nil];
NSString *result = @"";
for (int i=0;i<[str length];i++) {
NSInteger code = [str characterAtIdx:i] - 44032;
if (code > -1 && code < 11172) {
NSInteger choIdx = code / 21 / 28;
NSInteger jungIdx = code % (21 * 28) / 28;
NSInteger jongIdx = code % 28;
result = [NSString stringWithFormat:@"%@%@%@%@", result, [cho objectAtIdx:choIdx], [jung objectAtIdx:jungIdx], [jong objectAtIdx:jongIdx]];
}
}
return result;
}
2 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.