2010-07-13 8 views
2

J'ai une chaîne « AA - Le titre de la personne »objectif-c

Comment puis-je obtenir la partie avant le « - »?

La sortie devrait être « AA »

Aussi, si l'entrée ne dispose pas d'un « - » alors sortie doit être nul

Répondre

5
NSInteger hyphenStart = [theString rangeOfString:@" - "].location; 
if(hyphenStart == NSNotFound) 
    return nil; 
return [theString substringToIndex:hyphenStart]; 
+0

cela me donnera-t-il "AA" ou juste "AA"? – Yolanda

+0

il vous donnera "AA" –

+0

ok thx. Comment puis-je couper une chaîne dans obj-c? – Yolanda

0

avoir une lecture de la documentation de la classe NSString.