xxKralTRxx
Decapat
- Katılım
- 31 Temmuz 2022
- Mesajlar
- 342
- Çözümler
- 6
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp11
{
public partial class Form1 : Form
{
string _url;
public string VideoID
{
get
{
var yMATCH = new Regex(@"http(?:s?)://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)([\w\-]+)(&(amp;)?[\w\?=]*)?").Match(_url);
return yMATCH.Success? yMATCH.Groups[1].Value : string.Empty;
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_url = textBox1.Text;
webBrowser1.DocumentText = string.Format("<Meta http-equiv=\"X-UA-Compatible\" Content=\"IE=EDGE\" />" +
"<iframe width =\"100%\" height =\"315\" src =\"https://www.youtube.com/embed/{0}?autoplay=1 \"" +
" frameborder = \"0\" allow = \"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen ></ iframe >", VideoID);
}
}
}
Özellikle button1_click kısmının içerisindeki ve public string video kısmının içerisindeki yazılanlar ne anlama geliyor pek anlayamadım.
C#:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp11. { public partial class Form1 : Form. { string _url; public string VideoID. { get. { var yMATCH = new Regex(@"http(?:s?)://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)([\w\-]+)(&(amp;)?[\w\?=]*)?").Match(_url); return yMATCH.Success? yMATCH.Groups[1].Value : string.Empty; } } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { _url = textBox1.Text; webBrowser1.DocumentText = string.Format("<Meta http-equiv=\"X-UA-Compatible\" Content=\"IE=EDGE\" />" + "<iframe width =\"100%\" height =\"315\" src =\"https://www.youtube.com/embed/{0}?autoplay=1 \"" + " frameborder = \"0\" allow = \"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen ></ iframe >", VideoID); } } }
Evet orasını biliyorum ama hangi yazı ne işe yarıyor o noktalama işaretleri falan ne anlama geliyor? aşağıda yazdığımız kodun "Tuşa basıldığında bir YouTube videosunu açıyor galiba.
Tam bilgim yok fakat anladığım kadarıyla browser'ın bazı özelliklerini etkinleştiriyor (Picture in picture gibi) ve girilen linki düzgünce format'layıp kullanılabilir hale getiriliyor.Evet orasını biliyorum ama hangi yazı ne işe yarıyor o noktalama işaretleri falan ne anlama geliyor? aşağıda yazdığımız kodun "
string.Format("<Meta http-equiv=\"X-UA-Compatible\" Content=\"IE=EDGE\" />" +
"<iframe width =\"100%\" height =\"315\" src =\"YouTube{0}?autoplay=1 \"" +
" frameborder = \"0\" allow = \"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen ></ iframe >", VideoID);
}
"
anlamı ne?
Aslında bir önceki konumda da atmıştım videoyu bir oynatma listesinden proje yapıyordum ama bu derste yapılanlardan pek bir şey anlamadım.
Html kodu hocam. Ters slash anlamsız geldiyse çift tırnak kullanımından dolayı.Evet orasını biliyorum ama hangi yazı ne işe yarıyor o noktalama işaretleri falan ne anlama geliyor? aşağıda yazdığımız kodun "
string.Format("<Meta http-equiv=\"X-UA-Compatible\" Content=\"IE=EDGE\" />" +
"<iframe width =\"100%\" height =\"315\" src =\"YouTube{0}?autoplay=1 \"" +
" frameborder = \"0\" allow = \"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen ></ iframe >", VideoID);
}
"
anlamı ne?
Aslında bir önceki konumda da atmıştım videoyu bir oynatma listesinden proje yapıyordum ama bu derste yapılanlardan pek bir şey anlamadım.
Farklı bir dilden alıntı yani. Peki "Html kodu hocam. Ters slash anlamsız geldiyse çift tırnak kullanımından dolayı.
Bunun için de C# bilmeye gerek yok, kabaca Regex kodları var ve YouTube link denetleyicisi yazmışlar.Farklı bir dilden alıntı yani. Peki "
{
var yMATCH = new Regex(@"http(?:s?)://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)([\w\-]+)(&(amp?[\w\?=]*)?").Match(_url);
return yMATCH.Success? yMATCH.Groups[1].Value : string.Empty;
}
"
buradaki olay ne ?
Regex konusu üzerine biraz araştırma yapayım o zaman.Bunun için de C# bilmeye gerek yok, kabaca Regex kodları var ve YouTube link denetleyicisi yazmışlar.
"Bunları denetle, video_id al" kodu bu.
Sonra ilk attığınız kodda {1} alanlar var dikkat ederseniz video_id oraya yazıp direkt olarak video oynatıcısını getiriyor.
Regex zor gözükebilir ama mantığını kavrayınca çok şey yapılabilir, her dil özelinde. Hatta Regex ile kendi syntax'ını bile oluşturabilirsin uzmanlaşınca.Regex konusu üzerine biraz araştırma yapayım o zaman.