2010-09-22 6 views
0

i ont une chaînecomment faire un tableau de mots contenus dans une chaîne?

gpbusd buy update 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

je veux faire ensemble des mots contenus entre les espaces de ficelle? Comment puis-je faire?

+1

Est-ce que les mots ne signifient pas des nombres? – AlcubierreDrive

+1

Vous avez déjà reçu une réponse à cela dans votre question précédente - http://stackoverflow.com/questions/3767721/how-to-remove-a-particular-sign-from-a-string. il suffit de relire une réponse avec soin ... – Vladimir

+0

Quelle langue utilisez-vous? –

Répondre

3

Vous pouvez essayer avec

NSArray *words = [myString componentsSeparatedByString:@" "];

More here

0

Voici la réponse que vous cherchez ... ce vérifie plusieurs espaces aussi

remplacer str avec votre chaîne (i j'utilise str comme exemple)

NSMutableArray * arr;

NSString *[email protected]"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 

cela fonctionne très bien dans mon application. J'espère que cela vous aidera aussi

+0

merci ça marche –

Questions connexes