Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:52:40+00:00 2026-05-23T16:52:40+00:00

I use this code to retrive the first image of a feed… the htmlString

  • 0

I use this code to retrive the first image of a feed…
the htmlString contains html tags and in same cases I can get correctly the first image but in other cases i get a nil NSString. I don’t understand why. I’m sure that the htmlString contains one image. For example for this String I can’t get correctly the first image.

Example:
CultOfMac ha segnalato la disponibilità sul Mac App Store delle prime applicazioni sviluppate appositamente per OS X 10.7 Lion. In passato situazioni come questa hanno preceduto di qualche ora il lancio di nuovi prodotti, basti pensare al rilascio di iOS 4.2.1 per iPhone e iPad, primo firmware che ha unificato la numerazione delle versioni di sistema di questi dispositivi. OS X Lion è più vicino al rilascio?</p> <p><img class="aligncenter size-full wp-image-21789" title="mac-app-store_t" src="http://static.slidetomac.com/wp-content/uploads/2011/07/mac-app-store_t.jpg" alt="" width="507" height="300" /></p> <p><span id="more-21780"></span></p> <p>Solo qualche giorno fa Apple….

The part of code that I need is: <img class="aligncenter size-full wp-image-21789" title="mac-app-store_t" src="http://static.slidetomac.com/wp-content/uploads/2011/07/mac-app-store_t.jpg" alt="" width="507" height="300" /

But I can’t get correctly the url of the image…
What’s wrong in my code?
thanks

- (NSString *)getFirstImage:(NSString *)htmlString{



    NSString *urlImage=nil;
    NSScanner *theScanner = [NSScanner scannerWithString:htmlString];
    // find start of IMG tag
    [theScanner scanUpToString:@"<img" intoString:nil];
    do {
        [theScanner scanUpToString:@"src" intoString:nil];
        NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@"\"'"];
        [theScanner scanUpToCharactersFromSet:charset intoString:nil];
        [theScanner scanCharactersFromSet:charset intoString:nil];
        [theScanner scanUpToCharactersFromSet:charset intoString:&urlImage];

        if([urlImage rangeOfString:@"imagebutton.gif"].location == NSNotFound) return urlImage;


    }while (![theScanner isAtEnd]  );


    if([theScanner isAtEnd]) return nil;
     return urlImage;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:52:40+00:00Added an answer on May 23, 2026 at 4:52 pm

    What’s wrong in my code?

    You are using a scanning parser to parse HTML.

    HTML parsing is very very hard; all of the problems of an XML parser combined with a pervasive lack of consistency.

    Fortunately, HTML parsing is also very much a solved problem.

    Use a proper HTML Parser. libxml2 has an HTML compliant mode.

    There are a slew of question/answers on SO about HTML parsing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to update data in database table. Can reuse same code
I use this code to determine checkbox width and height: var chk = $('input[type=checkbox]:first');
I use this code: http://blogswizards.com/plugin-development/sliding-boxes-and-captions-with-jquery On a simple gallery site I am building. Specifically
I use this code to process a date string coming in from a json
I use this code which is taken from MVC futures and attach the Attribute
I use this code to generate a random number. Random R = new Random(0);
I use this code for drawing text in a panel: Graphics g = panel1.CreateGraphics();
i use this code to fill dropdownlist ViewData[projectType] = new SelectList (_dataManager.Project.ProjectTypeList(), Id, Name);
I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load(System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
i am trying to use this code to bind my asp.net menu control to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.