How to get a single NSString character from an NSString

前端 未结 4 1554
庸人自扰
庸人自扰 2021-01-30 15:56

I want to get a character from somewhere inside an NSString. I want the result to be an NSString.

This is the code I use to get a single character at index it:



        
4条回答
  •  暖寄归人
    2021-01-30 16:33

    This will also retrieve a character at index i as an NSString, and you're only using an NSRange struct rather than an extra NSString.

    NSString * newString = [s substringWithRange:NSMakeRange(i, 1)];
    

提交回复
热议问题