Combining Korean characters in Objective-C

I scratch my head over it.

I want to combine two Korean characters into one.

ㅁ + ㅏ = 마

How do I do this using NSString?


Edit:

zaph solution works with two characters. But I do not understand how to combine more than two.

ㅁ + ㅏ + ㄴ = 만

But

NSString *s = @"ㅁㅏㄴ";
NSString *t = [s precomposedStringWithCompatibilityMapping];
NSLog(@"%@", t);

displays

마ㄴ

Edit 2:

I looked around a bit and seemed a little busy. A character like "만" consists of 3 parts. Initial Jamo, Medial Jamo and Final Jamo. They must be combined to match the code point in the Khangul syllables using the equation below.

((initial * 588) + (medial * 28) + final) + 44032

This blog post has a very good explanation.

+4
source share
3 answers

'- (NSString *) precomposedStringWithCompatibilityMapping'.

NSString *tc = @"ㅁㅏ";
NSLog(@"tc: '%@'", tc);
NSString *cc = [tc precomposedStringWithCompatibilityMapping];
NSLog(@"cc: '%@'", cc);

NSLog:

tc: 'ㅁㅏ'
cc: '마'

. Apple Technical Q & A QA1235:

+4

Unicode. ㅁ (\ u3141) "hangul compatibility jamo", (, jamo). , , -\u1106. , \u1106, \u1161, Unicode: 마. , , .

+2

It's simple:

NSString *first = @"ㅁ";
NSString *second = @"ㅏ";

NSString *combinedStr = [first stringByAppendingString:second];

NSLog(@"%@", combinedStr); // ㅁㅏ
-4
source

Source: https://habr.com/ru/post/1542719/


All Articles