We can check if a URI is correctly or wrongly built using the IsWellFormedOriginalString()
method.
uri.IsWellFormedOriginalString()
uri
: The Uri instance we want to check if it is correctly built.
A Boolean is returned. If the URI is well-formed, then a true
is returned. Otherwise, false
is returned.
Let's look at the code below:
using System; class UriExample { //Entry point of Program static public void Main() { // Create some Uri objects Uri uri1 = new Uri("https://www.educative.io"); Uri uri2 = new Uri("https://google.com"); Uri uri3 = new Uri("http://maps.google.com/maps?q={!Account.BillingAddress}"); Uri uri4 = new Uri("https://www.hello.124/%%"); // check if they are correctly built Console.WriteLine(uri1.IsWellFormedOriginalString()); // True Console.WriteLine(uri2.IsWellFormedOriginalString()); // True Console.WriteLine(uri3.IsWellFormedOriginalString()); // False Console.WriteLine(uri4.IsWellFormedOriginalString()); // False } }
Uri
instances.Uri
instances were built correctly using the IsWellFormedOriginalString()
method, and then print the results.RELATED TAGS
CONTRIBUTOR
View all Courses