首頁  >  文章  >  後端開發  >  C# 程式檢查字串中的 URL

C# 程式檢查字串中的 URL

王林
王林轉載
2023-08-28 13:21:11871瀏覽

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";

現在我們需要檢查www或非www連結。為此,在C#中使用if語句−

if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) {
}

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);
      }
   }
}

輸出

True
#

以上是C# 程式檢查字串中的 URL的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除