views:

108

answers:

3

I'm interested in using rangeOfString with some wildcard characters as part of a search string.

For example, if I have several strings like "244px" and "356px" and I want to convert all such strings to "320px". Is there a way I can use wildcards to get the desired result?

+6  A: 

If you could use regex, you can do substitution for this pattern "[1-9][0-9]+px" to "320px"

S.Mark
+1, except that that wouldn't match "0px"
Dave DeLong
Oh, yes, correct. It was intentional, May be I shouln't limit that, So, To match any digits, please use `"[0-9]+px"` Don Wilson.
S.Mark
Can I use regex in an Objective C string like that?
Don Wilson
Yes. Please take a look this - http://stackoverflow.com/questions/845317/regex-solution-for-objective-c
S.Mark
+1  A: 

RegexKitLite is what you want, it has a small NSString extenstion class that lets you use the built-in regex libraries easily.

Kendall Helmstetter Gelner
A: 

Use NSNumberFormatter configured to the right pattern.

Mike Abdullah