I need to convert the searched text to a youtube search link, for example:
- search text:
the show must go on
- result:
https://www.youtube.com/results?search_query=the show must go on
And yes, I could "just" write a parser that would replace spaces with the plus sign, but spaces aren't the only thing that are getting replaced, for example:
- search text:
!@#$%^&*()
- result:
https://www.youtube.com/results?search_query=!@#$%^&*()
.
And so manually writing converter for every each special sign would be a really tedious and buggy mess.
And from what I've seen Youtube API doesn't have anything like that.
So, is there a API, dictionary or something else available that could do that for me?
CodePudding user response:
The thing you are looking for is URL Encoding, right?
string searchText ="the show must go on";
string searchUrlBase = "https://www.youtube.com/results?search_query=";
string searchUrl = searchUrlBase System.Net.WebUtility.UrlEncode(searchText);
Console.WriteLine(searchUrl);
This will give you Hello World
and !@#$%^&*()
will give you !@#$%^&*()
. Example added here