hii every one in my iphone app i have a search screen & i have some entries in the search bar like sudha, tharanga and womens era (some magazines ) suppose if we search cricket special, it has to show the respective magazine
so i planned to have the 开发者_如何学Ctable view data like follows
sudha (cricket special, anna hazare special)
tharanga (footbal special,x special)
womens era (some y special)
and while loading data to the table view by trimming the all data which is present between the brackets ( ) and should i display remaining in the table view
so how can i trim the string in such a way that it should remove the data with in brackets and bracket symbols
so that my table view data should become like this
sudha
tharanga
womens era
, thanx in advance
Regarding trimming the string as per your requirement, I guess the simplest way to go about it is to use the - (NSArray *)componentsSeparatedByString:(NSString *)separator
method as follows;
NSArray *anArray = [theFullString componentsSeparatedByString:@"("];
Assuming theFullString = @"womens era (some y special)"
, the resulting arrays first element would be as @"womens era "
. I assume this works fine.
Use this nnstring method to get the desired result,
- (NSString *)substringWithRange:(NSRange)range;
OR you can do that, first find bracket location,
int pointPos = -1;
for(int i=0; i<= [myString length]-1; i++){
if ([myString characterAtIndex:i] == '(') {
pointPos = i;
break;
}
}
NSString *finalString = [myString substringToIndex:pointPos];
精彩评论