2012-03-17 7 views
0

.txtドキュメントを読み込み、テキストブロックをNSStringsに格納したいと考えています。私の問題は、この文書に改行が含まれていることです。それらを取り除く方法はわかりません。順序付けされたNSArrayに個々の単語を入れて、その配列を調べてその情報を得ることができればいいと思います。このような私は何か:xcodeでのtxtドキュメントのパーサー

// txt file 
This is just a test. 
End of the text file. 

// NSArray and NSStrings 
NSArray *wholeDocument [email protected]"This","is","just","a","test","Foo","bar.", "End", "of", "the","text","file."; 
NSString *beginDocument [email protected]"This is just a test"; 
NSString *endDocument [email protected]"End of the text file."; 

答えて

0

はこれを試してみてください:ここで

NSString *str = [NSString stringWithContentsOfFile:@"file.txt"]; 
NSArray *arr = [str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

arrにスペースまたは改行のいずれかによって分離されているすべての単語が含まれています。