0

Hi i need some code to extract from a string like this

<div><a href="http://3.bp.blogspot.com/-uBx6ZoJ1DmY/TWPc1zD7aMI/AAAAAAAAANE/xeTZXtv4KYk/s1600/ipad-light-peak.jpg"><img border="0" height="260" src="http://3.bp.blogspot.com/-uBx6ZoJ1DmY/TWPc1zD7aMI/AAAAAAAAANE/xeTZXtv4KYk/s320/ipad-light-peak.jpg" width="320" /></a></div><div>Come ormai tutti sappiamo, il nuovo iPad 2 è già in produzione da un po' di tempo, e, secondo recentissime voci, il nuovo iPad sarà equipaggiato con Light Peak.&#160;</div><div><br /></div><div>Light Peak è una tecnologia sviluppata da Intel che utilizza la fibra ottica per la trasmissione dei dati, portando così la velocità di trasferimento dei dati da PC/Mac a iPad ad una velocità altissima.&#160;</div><div><br /></div><div>Una connessione Light Peak su iPad 2 è secondo noi alquanto improbabile, dato che ormai il dock a 30 pin è quasi uno "standard" di comunicazione dei dispositivi Apple; inoltre se su iPad 2 sarà presente solo Light Peak, tutte le case che producono accessori per iPad dovranno riprogettare il loro prodotti.</div><div><br /></div><div>E voi, cosa ne pensate ? Fatecelo sapere utilizzando il form qui sotto.</div><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/5674629894325206938-2710160962386980433?l=eugystyle.blogspot.com" alt="" /></div>

The path of the image... in this eìcode for esample I need the "http://3.bp.blogspot.com/-uBx6ZoJ1DmY/TWPc1zD7aMI/AAAAAAAAANE/xeTZXtv4KYk/s320/ipad-light-peak.jpg"

thanks

paul_1991
  • 231
  • 1
  • 7
  • 16
  • 3
    remove the regex tab before they address you to this http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 . Ops, I did... – Federico klez Culloca Feb 22 '11 at 19:48
  • sorry I don't understant – paul_1991 Feb 22 '11 at 20:29
  • Simple. Do **not** parse HTML with regular expressions. That way lies pain and madness. HTML is just not nice enough; it has some horrible corners. Use a proper HTML parsing library. Really. – Donal Fellows Feb 22 '11 at 23:59

1 Answers1

1

if you are not going to parse the html then a simple substringFromIndex and substringToIndex will do the trick.

NSString *yourFullURL = fullHTMLString;
NSRange t = [yourFullURL rangeOfString:@"\"><img border=\"0\""];

//check range exists
if(t.location !=NSNotFound){
    NSString *yourJPGURL = [yourFullURL substringToIndex:t.location];
}
// this will give you a new string up to the end of the URL//
// then repeat for the first part using a new NSRange for the beginning of
// the URL, use range.location+x  (where x is the number of characters to add as NSRange
// returns the beginning of the string you search for.
Willy
  • 9,681
  • 5
  • 26
  • 25
Nik Burns
  • 3,363
  • 2
  • 29
  • 37