Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate through the characters of an NSString

NSString *myStrings = @"abcdefghijklmnopqrstuvwxyz";

How could I iterate each of the letters (a, b, c, d, e, etc..) in an Objective-C for loop?

like image 679
Voldemort Avatar asked Aug 21 '11 23:08

Voldemort


1 Answers

One way is to use a simple for-loop:

for (NSInteger charIdx=0; charIdx<myStrings.length; charIdx++)
    // Do something with character at index charIdx, for example:
    NSLog(@"%C", [myStrings characterAtIndex:charIdx]);
like image 58
pythonquick Avatar answered Dec 26 '22 16:12

pythonquick