Read UTF8 character in specify position from a NSString

前端 未结 3 668
隐瞒了意图╮
隐瞒了意图╮ 2021-02-03 13:12

    NSString* str = @\"1二3四5\";
    NSLog(@\"%c\",[str characterAtIndex:0]); 
    NSLog(@\"%c\",[str characterAtIndex:1]);  

NSString - characterAtIndex works we

3条回答
  •  Happy的楠姐
    2021-02-03 13:51

    Why don't you try to use something like that:

    const char *yourWantedCharacter = [[yourSourceString substringWithRange:yourRange] UTF8String];
    

    where yourSourceString is your NSString object, yourRange is an NSRange object with the index of the needed character as the location parameter and an length parameter of '0' (zero).

提交回复
热议问题