Wildcards in strings - iphone

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?

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

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

Use NSNumberFormatter configured to the right pattern.

Related

Verbatim strings in PureScript

Does PureScript support verbatim string literals? Something like #"regex \s no escapes" in C#.
Alternatively is there support for regex literals as in JavaScript?
You can use triple-quote strings.
There are no regex literals AFAIK, but triple-quote strings might help there too. Example from docs:
regex """.+#.+\..+""" noFlags

Looking for method equivalent to find previous index of character in string in IOS

I have an string with some special characters.
The thing is, I want to search those special characters from the end of the string.
Is there any method available to search the index of character in backward direction?
Yes, use rangeOfCharacterFromSet:options:range: and use NSBackwardsSearch for the options argument.

Sed: use found string as a variable

I'm looking for a way to replace all instances of a form:
model->variable
with
models[variable][index]
where variable can be pretty much any combination of letters and numbers, probably defined like [0-9a-Z]{4,12}.
There are hundreds of such variables in the text. I need to know exact form of found string "variable" to use it in replacement. Is there a way to "remember" the string and use it later? Or any other method / software which could help in such case?
Thanks in advance.
If you could convert "variable" to uppercase by the way, it would be awesome.
You can use things in the pattern to replace with if you enclose it in \(...\). You then use \1 to insert the thing that was captured by the first such bracket.
A naïve solution to your problem would be this:
sed 's/model->\(.*\)/models[\1][index]/' file.txt

how to treat * as string and not as wildcard in lucene.net

I have a term test* and I want to treat it as string and not a wildcard of test.
How will I be able to do that in Lucene.Net. Any help???
Yes you can use a backslash to escape special characters. Both in the QueryParser and custom built searches. List of characters that require escaping can be found here.
If you're using the newer versions of Lucene.Net, you can use QueryParser.Escape("test*") to escape your search term. QueryParser.Escape() takes a string and returns the string after properly escaping all characters that are special for Lucene.

Matching beginning of words in a NSString

Is there a method built in to NSString that tokenizes the string and searches the beginning of each token? the compare method seems to only do the beginning of a string, and using rangeOfString isn't really sufficient because it doesn't have knowledge of tokens. Right now I'm thinking the best way to do this is to call
[myString componentsSeparatedByString:#" "]
and then loop over the resulting array, calling compare on each component of the string. Is this built-in and I just missed it?
Using CFStringTokenizer for, um, tokenizing strings will be more robust than splitting on #" ", but searching the results is still left up to you.
You may want to look into RegexKit Lite:
http://regexkit.sourceforge.net/#RegexKitLite/
Although it's a third party library, it's basically a very small (one class) wrapper built around the built-in fairly powerful regular expression engine.
It seems like this would be more useful since you could have non-capturing expressions match around the token-separators and then the capturing portion include or not include the text you are looking for along with the remaining text between tokens. If you have not used regular expressions much before, you'll want to read some kind of reference but just be aware you can separate out matching patterns from content you want to see with a cryptic but very powerful syntax.
I'm also not sure you can use CFStringTokenizer on the iPhone since the iPhone specific doc set has no reference for it.