Fernando68 Fernando68 - 22 days ago 16
C# Question

Check if a string in C# is a URL

This has been asked before here, but the answers are all PHP related.
Is there a similar and working solution using C#? Like a specific test class or routine?
I want to parse www.google.com or google.com or mywebsite.net etc... with or without prefixes.
Thanks

Answer

C# has Regex as well, but this seems simpler:

bool isUri = Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute);

(Answered at Regular expression for URL)

Comments