Home >Backend Development >C#.Net Tutorial >C# program to check URL in string
Use the StartWith() method in C# to check for URL in a String.
Let us say our input string is −
string input = "https://example.com/new.html";
Now we need to check www or non-www links. To do this, use an if statement in C# −
if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) { }
You can try to run the following code to check for URL in a string.
Live Demo
using System; class Demo { static void Main() { string input = "https://example.com/new.html"; // See if input matches one of these starts. if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) { Console.WriteLine(true); } } }
True
The above is the detailed content of C# program to check URL in string. For more information, please follow other related articles on the PHP Chinese website!