Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[C#] String.Split

Empfohlene Antworten

Veröffentlicht

Hallo,

ich würde gerne aus einem YouTube Link folgendes extrahieren:

http://www.youtube.com/watch?v=kLwrdp8RV5A

Meine Anfangsidee war, es mit der string.split-Methode zu versuchen... Leider klappt das nicht ganz so, wie ich das will.

Wie kriege ich es jetzt hin, dass ich aus einem YouTube-Link nurnoch das watch?v=123 herausbekomme?

Grüße

  • Autor

Ich habe vor, mir ein tool zu schreiben, was mir sagt, ob meine YouTube-Bookmark-Links noch erreichbar sind, oder entfernt wurden (Copyright, oder vom Nutzer)... Ich glaube, es klappt soweit :P

Erstmal rudimentär zusammengestöpselt


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.IO;


namespace WebsiteReader

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            //MessageBox.Show(splitUrl(textBox1.Text));

            string url = textBox1.Text;

            string splittedUrl = splitUrl(textBox1.Text);

            string response = GetUrlResponse(textBox1.Text, "", "");


            richTextBox1.Text = response;


            int a = richTextBox1.Text.IndexOf(splittedUrl, 0);


            if (a == -1)

            {

                MessageBox.Show("nicht gefunden");

            }

            else

            {

                MessageBox.Show("gefunden");

            }


        }


        private string splitUrl(string url)

        {

            // Funktioniert: http://www.youtube.com/watch?v=kLwrdp8RV5A

            // Funktioniert nicht: http://www.youtube.com/watch?v=j5-yKhDd64s

            // Unterschied:

            // Funktioniert: <link rel="canonical" href="/watch?v=kLwrdp8RV5A">

            // Funktioniert nicht: <link rel="canonical" href="/?gl=DE&hl=de">


            string[] abc = url.Split('/', '&');

            string splittedUrl = "/"+abc[3];


            if (splittedUrl.Contains("/watch?v=") == true)

            {

                return splittedUrl;

            }

            else

            {

                return "fehler";

            }

        }


        public static string GetUrlResponse(string url, string username, string password)

        {

            string content = null;


            WebRequest webRequest = WebRequest.Create(url);


            if (username == null || password == null)

            {

                NetworkCredential networkCredential = new NetworkCredential(username, password);

                webRequest.PreAuthenticate = true;

                webRequest.Credentials = networkCredential;

            }


            WebResponse webResponse = webRequest.GetResponse();


            StreamReader sr = new StreamReader(webResponse.GetResponseStream(), Encoding.ASCII);

            content = sr.ReadToEnd();


            return content.ToString();

        }

    }

}



String url = "http://www.youtube.com/";

String result = "http://www.youtube.com/watch?v=kLwrdp8RV5A".Substring(url.length);

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.