NSString stringByReplacingOccurrencesOfRegex

发布于 2024-12-02 19:08:14 字数 140 浏览 0 评论 0原文

我看到了这个方法的很多用法:stringByReplacingOccurrencesOfRegex on NSString on SO。但我收到一个警告,说找不到此实例方法,并且在运行时因“发送到......无法识别的选择器”而崩溃,

有什么想法吗?

I saw a lot of usages of this method: stringByReplacingOccurrencesOfRegex on NSString on SO. But I got a waring that said this instance method is not found and at running time crashing with a "unrecognized selector sent to.."

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喵星人汪星人 2024-12-09 19:08:14

该方法是 RegExKitLite 提供的扩展。

That method is an extension provided by RegExKitLite.

还给你自由 2024-12-09 19:08:14

我从来没有见过这种方法,但你可以使用这个方法来实现正则表达式操作:

/* Replace all occurrences of the target string in the specified range with replacement. Specified compare options are used for matching target. If NSRegularExpressionSearch is specified, the replacement is treated as a template, as in the corresponding NSRegularExpression methods, and no other options can apply except NSCaseInsensitiveSearch and NSAnchoredSearch.
*/
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options range:(NSRange)searchRange NS_AVAILABLE(10_5, 2_0);

抱歉,格式限制迫使它分成两行,请查看 NSString.h 以获取此代码

I've never seen that method, but you can use this one to achieve regular expression manipulation:

/* Replace all occurrences of the target string in the specified range with replacement. Specified compare options are used for matching target. If NSRegularExpressionSearch is specified, the replacement is treated as a template, as in the corresponding NSRegularExpression methods, and no other options can apply except NSCaseInsensitiveSearch and NSAnchoredSearch.
*/
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options range:(NSRange)searchRange NS_AVAILABLE(10_5, 2_0);

Sorry about the formatting restrictions forcing it onto two lines, check out NSString.h for this code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文