Searching within NSString

前端 未结 2 1357
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-16 10:52

I have an NSString that is of the following pattern:

Hello


No.: 123456789123
Age: 21

Country: xxx

How can I search within said string so

2条回答
  •  孤街浪徒
    2021-01-16 11:05

    rangeOfString: will return the range of the string you are searching for. To extract this range from the original string, use substringWithRange:.

    Edit: If the string you are looking for is unknown (and you want to search for the "No." string and extract everything that comes behind it, NSScanner is one good way to go.

提交回复
热议问题