NSMutableArray*array = [[NSMutableArray alloc]init];
NSArray*Somearray = [NSArray arrayWithObjects:1st Object,2ndObject,3rd Object,4th object,5th Object,nil];
在上述陣列第一對象,2ndObject,第三對象,第四對象,具有VAL,內容,結束在每個索引第五對象。如何獲取NSArray中的索引?
for(int i=0;i<[Somearray count];i++)
{
______________
Here the code is there to give each index ,that is having val,content,conclusion ..
After that val,content,conclusion in each index will be add to Dict..
____________
NSDictionary *Dict = [NSDictionary dictionaryWithObjectsAndKeys:val,@"val",content,@"content",conclusion,@"conclusion",nil];
//Each time adding dictionary into array;
[array addObject:Dict];
}
上述字典是在for循環和鍵值對將被添加的5倍(計數的someArray)。現在陣列具有
array = [{val="1.1 this is first one",content="This is the content of 0th index",conclusion="this is the conclusion of 0th index"},{val="1.2 this is first one",content="This is the content of 1st index",conclusion="this is the conclusion of 1st index"},____,____,______,{val="1.5 this is first one",content="This is the content of 4th index",conclusion="this is the conclusion of 4th index"},nil];
現在我具有NSString*string = @"1.5";
現在我需要其中val是具有it.How 1.5至在發送給STR陣列找到的索引的索引。
任何人都可以共享代碼,請。
在此先感謝。
如何使用有前綴的方法 – Univer
'[ id objectForKey:@「val」] hasPrefix:@「1.5」]'檢查* [NSString類參考](http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class /Reference/NSString.html#//apple_ref/occ/instm/NS字符串/ hasPrefix:)*。 –