Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace specific words in html string
    primarykey
    data
    text
    <p>I have dynamic string that currentString. For example currentstring like :</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;meta content="width=320.000000, initial-scale=0.47, maximum-scale=1.0, user-scalable=1" name="viewport"&gt;&lt;/head&gt;&lt;body&gt;&lt;table width="510" cellpadding="0" cellpadding="0"&gt;&lt;tr&gt;&lt;td valign="top"&gt;&lt;p&gt;&lt;a href="http://erhandemirci.blogspot.com/masak-in-baskani-neden-gorevden-alindi-haberi-828402.html"&gt;&lt;img src="http://erhandemirci.blogspot.com/images//news/r-farukeliedioglu-300200-828402.jpg" width="72" height="48" style="border: 1px #000000 solid;" hspace="2" align="left"&gt;&lt;/a&gt;content...........&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p>I want to change table tag's width from 510 to 0. I tried following code but it's not working . </p> <pre><code>NSString *currentString = @"&lt;html&gt;&lt;...width &gt; &lt;table width="" .... &gt; dynamic string"; // Regular expression to find "word characters" enclosed by {...}: NSRegularExpression *regex; regex = [NSRegularExpression regularExpressionWithPattern:@"\\table width=\"(\\w+)\\\"" options:0 error:NULL]; NSMutableString *modifiedString = [currentString mutableCopy]; __block int offset = 0; [regex enumerateMatchesInString:currentString options:0 range:NSMakeRange(0, [currentString length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { // range = location of the regex capture group "(\\w+)" in currentString: NSRange range = [result rangeAtIndex:1]; // Adjust location for modifiedString: range.location += offset; // Get old word: NSString *oldWord = [modifiedString substringWithRange:range]; // Compute new word: // In your case, that would be // NSString *newWord = [self replaceWord:oldWord]; NSString *newWord =@"0"; // Replace new word in modifiedString: [modifiedString replaceCharactersInRange:range withString:newWord]; // Update offset: offset += [newWord length] - [oldWord length]; } ]; NSLog(@"modified%@", modifiedString); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload