Change numbers in NSString

Discussion in 'iOS Programming' started by newtoiphonesdk, Jul 8, 2012.

  1. newtoiphonesdk macrumors 6502a

    Jul 30, 2010
    I am working on a blog app. I parse the RSS feed and then take one of the item elements and build html string. I have to leave the UIWebView Scales To Fit turned off, or the text all gets shoved into one page, and is too small to read. If I turn on scales to fit on the UIWebView, the text is perfect, but if larger pictures are in the blog, they stretch well off the width of the page. One such picture is

    img class="aligncenter size-full wp-image-4532" title="Father_and_daughter_1" src="" alt="" width="590" height="342" /

    In this case, the width goes well beyond 320px. Is there any way I could use regex or something to detect if the width is greater than 320, and if so, have it replace the width and height by something that would fit?
  2. newtoiphonesdk thread starter macrumors 6502a

    Jul 30, 2010
    Change numbers in NSString

    I'm having an issue with replacing string by occurence of string methods
    The string I want to change is:

    <img class="alignleft size-full wp-image-4539" title="divorce" src="" alt="" width="226" height="170" />

    All I want to do is replace the width and height numbers to a standard set...any suggestions?
  3. SiriusBlack macrumors newbie

    Jul 9, 2012
    Here's an example of use for the occurrences of string method:

    So just substitute the occurrences you'd like to change in.

  4. MattInOz macrumors 68030


    Jan 19, 2006
    Have a look at NSString method
    - (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)aSet options:(NSStringCompareOptions)mask range:(NSRange)aRange
    Set it to search backwards with a Numeral Character set and the range set firstly to the full string. That should return a range for the characters that describe the height. Which you could then mutate. Then on the second pass reduce the search range so that it all the string before the first find and that should get you the range of the characters that describe the width.

Share This Page