c# parsing a string to 2 seprate string values

mion shion 241 Reputation points
2022-10-23T22:21:12.55+00:00

Good evening all,

i have been trying to get this to work for a while now,

so example of the text.

Found YouTube URL for "Faceless 1-7 - Download My Conscious" : https://www.youtube.com/watch?v=1d2ovu4IMdE

i want just the stuff insde the "" and the youtube url

i have tryied.

        public void splitstrings(string path)  
        {  
                if(path.Contains("Found YouTube URL for"))  
            {  
                var content = path;  
                var parts = content.Split(':'); // split on spaces  
  
                var string1 = parts.First();  
                var string3 = parts.Last();  
                var theRest = content;  
                string1.Replace("Found YouTube URL for \"\" ","");  
            }  
                else  
            {  
  
            }  
  
              
        }  

so what i want as a result is,

string 1 to be Artist's name ( the text inside the quotes ) and,
string 2 to be the youtube url,

but cant seem to get the desired result as it wont remove anything just give me a print out of it unedited

thank you in advance.
elfenliedtopfan5

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,940 questions
0 comments No comments
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2022-10-24T03:41:07.757+00:00

    How to proceed depends very much on how consistent is the
    data format. Assuming all lines have the same format as
    the example, then maybe this example will give you some
    ideas.

    static void Main(string[] args)  
     {  
         string path =  
             @"Found YouTube URL for ""Faceless 1 - 7 - Download My Conscious"" : " +  
             "https://www.youtube.com/watch?v=1d2ovu4IMdE";  
         int x = path.IndexOf("\"");  
         int y = path.IndexOf("\"", x+1);  
         string title= path.Substring(x+1, y - x - 1);  
      
         int urlstrt = path.IndexOf("http");  
         string url = path.Substring(urlstrt);  
      
         Console.WriteLine(title);  
         Console.WriteLine(url);  
      
         Console.ReadLine();  
      
     }  
       
     /*  
    Faceless 1 - 7 - Download My Conscious  
    https://www.youtube.com/watch?v=1d2ovu4IMdE  
    */  
    
    • Wayne
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.