Skip to content

Instantly share code, notes, and snippets.

@Edkorenkov
Created June 21, 2022 09:44
Show Gist options
  • Save Edkorenkov/ded9864d8ef2f7dfec549db0ac6b1e0d to your computer and use it in GitHub Desktop.
Save Edkorenkov/ded9864d8ef2f7dfec549db0ac6b1e0d to your computer and use it in GitHub Desktop.
Validate Uri in .NET
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