2016-08-12 22 views
0

私はPygLatin Appを構築しており、文字列を文字配列に分割する方法を知りたいと考えています。例えば文字列を文字配列に分割する - Objective-C

ユーザの入力が「Hello World」の私は、後に母音の配列と比較できるように、[@"h",@"e",@"l",@"l",@"o"]としてそれを格納する配列変数にhelloを分割できるようにしたい場合。

答えて

-1

これらの機能は、その操作に役立ちます。

NSString *[email protected]"hello world"; // your string 
NSArray *items = [str componentsSeparatedByString:@" "]; //split string with separator 
NSString *str1=[items objectAtIndex:0]; // get the first string 
SString *str2=[items objectAtIndex:1]; 

for (int i=0; i < [str1 length]; i++) { 
unichar mycharacter = [str1 characterAtIndex:0]; 
NSString * mycharasstring= [NSString stringWithFormat:@"%c", mycharacter]; 
[self.myarray addobject: [myString characterAtIndex:i]]; // add characters to your array 

} 
+1

これは、コードがU + 10000以上(Emojiなど)のUnicode文字では機能しません。 – rmaddy

+0

@rmaddyはい単純な文字列のための単なる単純な解決策であると確信しています。この問題を解決するためのよりよい解決策を提供できますか?私は助けようと努力している学生です:) –

+0

重複した質問の答えを見てください。ところで - 私の下投票はありません。 – rmaddy