Split Youtube URL with Embedcode video code ASP.NET (C#)


 protected string SplitURL()
    {
        string strFEmbCode=null;
        //string strURL = "http://www.youtube.com/watch?v=j2f7hmRUo9Q&feature=g-logo&context=G2b9833eFOAAAAAAACAA";
        string strURL = "http://www.youtube.com/embed/J4oJWUJpbLY?hd=1";
        String[] Array = strURL.Split('/');
        if (Array.Length > 0)
        {
            for (int i = 0; i < Array.Length; i++)
            {
                if (Array[i].Contains("watch?v"))
                {
                    string strEmbdCode = Array[i];
                    String[] strArrEmbedCode = strEmbdCode.Split('?');
                    String[] strEmbedCode = strArrEmbedCode[1].Remove(0, 2).Split('&');
                    strFEmbCode = strEmbedCode[0].ToString();
                 }
                 if (Array[i].Contains("?"))
                 {
                     string strEmbdCode = Array[i];
                     String[] strEmbedCode = Array[i].Split('?');
                     strFEmbCode = strEmbedCode[0].ToString();
                 }
            }
        }
        return strFEmbCode;
    }

Comments

TARUN said…
hi this is tarun. my mail id is tarun00198@gmail.com

tou article is good but it woking for thr two types of urls only that u specify in the code.. but you tube video url are in diffrenet types like below
http://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index
http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/QdK8U-VIH_o
http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0
http://www.youtube.com/watch?v=0zM3nApSvMg#t=0m10s
http://www.youtube.com/embed/0zM3nApSvMg?rel=0
http://www.youtube.com/watch?v=0zM3nApSvMg
http://youtu.be/0zM3nApSvMg

how to get the embeded code for the all the above types
please help me out
VedPathak said…
Hi Tarun,
Thanks for showing your kind interest. You can split the Youtube URL as per your requested URL you need check for all the possibilities as you have mentioned and split them accordingly.

Thanks.