Objective-C NSString for loop with characterAtIndex

后端 未结 4 698
逝去的感伤
逝去的感伤 2021-02-04 16:46

I\'m trying to loop through a NSString, character by character, but I\'m getting a EXC_BAD_ACCESS error. Do you have an idea how to do this right? I\'ve been googling for hours

4条回答
  •  时光取名叫无心
    2021-02-04 17:28

    If you want to find the location of a character in a string you can use this:

    NSUInteger position = [text rangeOfString:@"."].location;
    

    if the character or text is not found you will get a NSNotFound:

    if(position==NSNotFound)
        NSLog(@"text not found!");
    

提交回复
热议问题