Split an NSString to access one particular piece

后端 未结 7 1643
轮回少年
轮回少年 2020-11-27 11:59

I have a string like this: @\"10/04/2011\" and I want to save only the \"10\" in another string. How can I do that?

7条回答
  •  感动是毒
    2020-11-27 12:42

    Objective-c:

         NSString *day = [@"10/04/2011" componentsSeparatedByString:@"/"][0];
    

    Swift:

         var day: String = "10/04/2011".componentsSeparatedByString("/")[0]
    

提交回复
热议问题