Main Contents

Parcourir un NSString en Objective-C

octobre 29, 2008

Voilà un bout de code pour parcourir une chaîne caractère par caractère. Si ça peut aider quelqu’un 🙂

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *MonTexte;
MonTexte=@"helloworld";
NSInteger i = MonTexte.length;
unichar Lettre;
for(int j =0; j<i;j++) {
Lettre = [MonTexte characterAtIndex:j] ;
NSLog(@"Mon texte est %@, la lettre est %c et la longeur totale %i",MonTexte, Lettre, i);
}
[pool drain];
return 0;
}

Catégorie(s): Développement, Objective-C, Tutorial | Comments (1)

Un commentaire