Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If i have the iframe of a video like this:
HTML
<iframe width="395" height="295" src="//www.youtube.com/embed/fdbazqdXBeE" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

and I want to get the source "src" only, how can I do this using C#.

Thanks in advance.
Posted
Comments
Sampath Lokuge 29-Sep-13 8:38am    
Can you explain the whole scenario here ? Which way you're going to send src value to the server and etc. ?

1 solution

One way is to use regular expressions. Consider the following:
C#
string testString = "<iframe width=\"395\" height=\"295\" src=\"//www.youtube.com/embed/fdbazqdXBeE\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";

System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex("src=\"(.*?)\"");

if (re.IsMatch(testString)) {
   System.Console.WriteLine(re.Match(testString).Value);
   System.Console.WriteLine(re.Match(testString).Value.Substring(5).TrimEnd('"'));
}

The output is:
src="//www.youtube.com/embed/fdbazqdXBeE"
//www.youtube.com/embed/fdbazqdXBeE
 
Share this answer
 
Comments
Member 10304621 29-Sep-13 9:53am    
Thank you it works for me
Wendelius 29-Sep-13 11:18am    
Glad it helped :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900