Created
June 21, 2022 09:44
-
-
Save Edkorenkov/ded9864d8ef2f7dfec549db0ac6b1e0d to your computer and use it in GitHub Desktop.
Validate Uri in .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
public static bool IsValidUri(string input) => Uri.IsWellFormedUriString(input, UriKind.Absolute); | |
// Input: https://www.youtube.com/watch?v=dfzBMxXQUOc | |
// Output: dfzBMxXQUOc | |
static string? GetYouTubeVideoId(string input) | |
=> HttpUtility.ParseQueryString(new Uri(input).Query).Get("v"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment