How to convert string to array in objective C?

前端 未结 5 1209
不思量自难忘°
不思量自难忘° 2021-02-06 08:35

How to convert string to array in objective C. i.e,I have a string,

NSString *str = @\"Hi,How r u\";

This should be converted into an array *NS

5条回答
  •  别那么骄傲
    2021-02-06 09:40

    You have to do,

    NSString *str = @"Hi,How r u";
    NSArray *arr = [str componentsSeparatedByString:@" "];
    

    And, in order for this to work as you expect, there should be a white-space between "Hi," and "How". Your string should look like @"Hi, How r u".

提交回复
热议问题