0

hihi,

I have this html text response from a particular website:

<tr><td valign="top"><img src="/icons/image2.gif" alt="[IMG]"></td><td><a href="crsdsdfs2221.jpg">crash-2221.jpg</a></td><td align="right">14-Jun-2010 14:29  

Notice for every line, there is this href="_____.___", which is an image file with random name and random format. I would like to extract that string within the inverted commas out so that i can append it into a URL path and download the image. I've been looking through this documentation from apple:

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/strings/Articles/SearchingStrings.html#//apple_ref/doc/uid/20000149-CJBBGBAI

on String programming but couldn't find one that fits my bill. Also after reading it, what code can I use to ensure that I will be reading the next line the next time my function is called( because I want to download the next picture). Hope some kind soul can help me out, thanks!

1 Answer 1

1

Four methods in the NSString class can get you the info you want.

  • componentsSeparatedByString: is how you will separate your responses by line. Give it a string parameter that occurs once per line and then examine each component individually.
  • rangeOfString: can find the indicies of specific substrings that occur in your string. Use it to get the index of strings that you know will be there, like @"img src=\"" and @"a href=\""
  • substringFromIndex: and substringToIndex: Use these in conjunction with rangeOfString to surgically subtract the information you need. The fact that the filenames you want are between quotation marks will be a big help in your case.

Hope this leads you in the right direction.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.