Substring with range out of bounds?

前端 未结 4 1640
一生所求
一生所求 2020-12-20 17:29

Okay, so this is a bit confusing (well to me). I have a string that has a single number I want out of it. I have surrounded this number with \'/\' so that I will be able to

4条回答
  •  执念已碎
    2020-12-20 18:09

    I don't know why your are using this approach, but iOS provides a string function which separates a string with respect to another string and returns an array of the components. See the following example:

    NSString * str = @"dadsada/2/dsadsa";
    NSArray *listItems = [str componentsSeparatedByString:@"/"];
    NSString *component = [listItems objectAtIndex:1];
    

    Now your component string should have 2 store in it.

提交回复
热议问题