在NSString中搜索 [英] Searching within NSString

查看:82
本文介绍了在NSString中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSString,其格式如下:

I have an NSString that is of the following pattern:

Hello


No.: 123456789123
Age: 21

Country: xxx

如何在所述字符串中搜索以便将123456789123作为新字符串?

How can I search within said string so that i get "123456789123" as a new string?

推荐答案

rangeOfString:将返回您要搜索的字符串的范围。要从原始字符串中提取此范围,请使用 substringWithRange:

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

编辑:如果字符串为正在寻找的是未知的(你想要搜索号字符串并提取它背后的所有内容, NSScanner 是一个很好的方法。

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.

这篇关于在NSString中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆