how to make array of words contained in string?
i have a string
gpbusd buy upd开发者_StackOverflow社区ate HIT 40 PIPS HIT 110 PIPS gpbusd buy BREAK EVEN update HIT 100+ gpbusd buy 1.5500/25 1.5455 new 40 100+ gpbusd buy update CLOSE 0 TO 10 PIPS N gpbusd buy 1.5335/50 1.5320 new 40 80+ gpbusd buy update 15-20 PIPS CLOSE KEEP OPEN gpbusd buy 1.5530/50 1.5505 update HIT 80 KEEP OPEN gpbusd buy 1.5530/50 1.5465 new 40 80 100+ gbpjpy sell 131.05/.130.75 132.15 new 60 100 keep open eurusd sell 1.2840/20 1.2870 STOP update
i want to make array of the words contained between spaces of string?how can i do it?
You can try with
NSArray *words = [myString componentsSeparatedByString:@" "];
More here
here is the answer you are looking for...this will check multiple spaces also
replace str with your string(i am using str as an example)
NSMutableArray *arr;
NSString *str=@"mango apple banana grapes pineapple";
NSRange match;
arr=[[NSMutableArray alloc]init];
while(str.length>0)
{
match = [str rangeOfString: @" "];
if(match.location>=str.length)
{
[arr addObject:str];
break;
}
NSString *str2=[str substringToIndex:match.location];
str=[str substringFromIndex:match.location+1];
if(str2.length==0)
{
continue;
}
[arr addObject:str2];
}
NSLog(@"array is %@",arr); //here is your array
this is working fine in my app. hope it will also help you
精彩评论