Replacing in NSString with wildcards / regular exp

2020-02-02 03:24发布

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?

3条回答
Melony?
2楼-- · 2020-02-02 04:03

You could also use NSScanner on this quite easily. A quick read through this will give you all you need to know:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/Scanners.html#//apple_ref/doc/uid/20000147-BCIEFGHC

查看更多
Viruses.
3楼-- · 2020-02-02 04:07

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.

查看更多
在下西门庆
4楼-- · 2020-02-02 04:07

You could use straight C stuff. Here is a regex library allowing you to use NSString. This site has a small example of use.

查看更多
登录 后发表回答