C# program to check URL in string

王林
Release: 2023-08-28 13:21:11
forward
926 people have browsed it

C# 程序检查字符串中的 URL

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";
Copy after login

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")) {
}
Copy after login

Example

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);
      }
   }
}
Copy after login

Output

True
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template