views:

9

answers:

1

In my app, I want to replace some variables inside an html file when it goes to an UIWebView. The file is local. For example, I add a variable $userName$ and then I would replace that with @"John".

Would I have to read the file in as string, and then perform some string replacement action?

+2  A: 

Yes, that should work... take a look at the replaceOccurrencesOfString:withString:options:range: method of NSMutableString. If there is much content and the position of your variable is not known exactly but is to be expected within known limits (for example within the first 100 characters), you might want to provide a range to reduce the overhead from comparing the whole content to the term you're about to replace. If the position of the variable is fixed, you could use replaceCharactersInRange:withString: instead. This would eliminate the performance penalty of comparing every part of the string to the string you're about to replace completely.

Toastor