Split an NSString into an array in Objective-C

前端 未结 4 617
傲寒
傲寒 2021-02-05 14:23

How can I split the string @\"Hello\" to either:

  • a C array of \'H\', \'e\', \'l\', \'l\', \'
4条回答
  •  迷失自我
    2021-02-05 14:26

    A user529758 mentions, split your string - the C way - like:

    const char *array = [@"Hello" UTF8String];
    

    But then loop it using:

    for (int i = 0; i < sizeof(array); i++) {
      doSomethingWithCharacter(array[i]);
    }
    

提交回复
热议问题