LightNight LightNight - 6 days ago 5
Objective-C Question

Change html tag in NSString

For example I have html string:

<p>
<img mce_src="http://example.com/apple.png" src="http://example.com/apple.png" width="512" height="512" style="">
<br mce_bogus="1">
</p>


How can I change this properties:
width="512" height="512"
to for example:
width="123" height="123"
?

Thanks

Answer

You should go with regular expressions and try the RegexKitLite library.

NSString *regex = @"(=\"[0-9]+\")";

NSString *replaced = [htmlString stringByReplacingOccurrencesOfRegex:regex usingBlock:^NSString *(NSInteger captureCount, NSString * const capturedStrings[captureCount], const NSRange capturedRanges[captureCount], volatile BOOL * const stop) {
  return(@"123");
}];
Comments