hi,
i have a NSString that is of the follow :
Hello
(\n)
(\n)
No.: 123456789123
Age: 21
(\n)
Country: xxx
how can i search within a string so that i get "123456789123" as a new string?
thx in advance
hi,
i have a NSString that is of the follow :
Hello
(\n)
(\n)
No.: 123456789123
Age: 21
(\n)
Country: xxx
how can i search within a string so that i get "123456789123" as a new string?
thx in advance
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.
I think [yourString substringWithRange:[yourString rangeOfString:@"123456789123"]]
should give you what you want.
Presumably you have a variable with the value "123456789123", in which case you would do [yourString substringWithRange:[yourString rangeOfString:otherString]]
.
For more information, see the NSString class reference.