在NSString中替换为通配符/正则表达式 - 可可 [英] Replacing in NSString with wildcards / regular expressions - cocoa

查看:132
本文介绍了在NSString中替换为通配符/正则表达式 - 可可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  NSString * x = @\/ Sagar\'和\'Samir\'; 
\/



\'



预期输出

  x =(应该有)@和\'Samir\'

,Ms word给一些选项在find&替换,使用通配符。
(只是举例)



可可吗?

解决方案

我假设你一般寻找一个解决方案 - 不是为这个特定的字符串。您需要了解正则表达式



对于Objective-C中的正则表达式支持,请参阅 RegexKitLite 。它提供了支持各种正则表达式匹配和替换的NSString类别方法。


NSString *x=@"\"/Sagar\' and \'Samir\' ";

Now, I want to remove characters between these.

\" /

\'

Intended output

x = (should have) @"and \'Samir\'"

So, Ms word give some options in find & replace, using wild card characters. ( just giving example )

Is it possible in cocoa?

解决方案

I'll assume you're looking for a solution in general -- not for this particular string. You'll want to learn about regular expressions.

For regular expression support in Objective-C check out RegexKitLite. It provides category methods on NSString that support various regex matching and substitution.

这篇关于在NSString中替换为通配符/正则表达式 - 可可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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