この質問の前に、お詫びをさせてください。私は Objective C に非常に慣れていません。残念ながら、仕事のプロジェクトのタイムラインが非常にタイトで、できるだけ早くスピードアップする必要があります。
以下のコードは機能します。これを処理するためのより良い方法があるかどうか疑問に思っています...おそらくもっとココアっぽいものです。関数の全体的な目的は、特定の値を持つ文字列内の位置の順序付きリストを取得することです。
快適さの理由から、標準の配列に戻りました。最初に宣言する NSMutableString は、テスト目的のみです。この言語の完全な初心者であり、Objective C (および私が推測する C++) が変数とポインターを処理する方法に頭を悩ませています。あらゆるヒント、ヒント、ポインターを歓迎します。
NSMutableString *mut = [[NSMutableString alloc] initWithString:@"This is a test of the emergency broadcast system. This is only a test."];
NSMutableArray *tList = [NSMutableArray arrayWithArray:[mut componentsSeparatedByString:@" "]];
int dump[(tList.count-1)];
int dpCount=0;
NSUInteger length = [mut length];
NSRange myRange = NSMakeRange(0, length);
while (myRange.location != NSNotFound) {
myRange = [mut rangeOfString:@" " options: 0 range:myRange];
if (myRange.location != NSNotFound) {
dump[dpCount]=myRange.location;
++dpCount;
myRange = NSMakeRange((myRange.location+myRange.length), (length - (myRange.location+myRange.length)));
}
}
for (int i=0; i < dpCount; ++i) {
//Going to do something with these values in the future... they MUST be in order.
NSLog(@"Dumping positions in order: %i",dump[i]);
}
text2.text = mut;
[mut release];
返信ありがとうございます。