Community discussion forum

get image link from string

  • 1 year ago
    Hi, I am looking how to search a string for the first instance of text 'img src=' Then select the text in the quotes after it. This then leaves me with the link to the image. For example... img src="http://website/str_strip/000000000/00000000/0000000/30223.print.gif" Thanks for any help...
  • 1 year ago
    //Capture the image url however you like string myImageUrl = "img src=\"http://website/str_strip/000000000/00000000/0000000/30223.print.gif\""; //Create a delimiter string, convert to char[] to pass to String.Split() string delimiterString = "\""; char[] delimiter = delimiterString.ToCharArray(); //Call String.Split() and pass the delimiter string[] results = myImageUrl.Split(delimiter); Console.WriteLine(results[1]); // Writes http://website/str_strip/000000000/00000000/0000000/30223.print.gif This is one way to do it, and just the first one I thought of. You may have to change the delimiter based on how your URL looks. Hope this helps!
  • 1 year ago
    Well it looks like it destroyed my formatting. Sorry, I'm not used to this forum yet. //Capture the image url however you like string myImageUrl = "img src=\"http://website/str_strip/000000000/00000000/0000000/30223.print.gif\""; //Create a delimiter string, convert to char[] to pass to String.Split() string delimiterString = "\""; char[] delimiter = delimiterString.ToCharArray(); //Call String.Split() and pass the delimiter string[] results = myImageUrl.Split(delimiter); Console.WriteLine(results[1]); // Writes http://website/str_strip/000000000/00000000/0000000/30223.print.gif
  • 1 year ago
    LOL, I give up. :)

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback