檢查字串中的 URL 的 C# 程式
在 C# 中使用 StartWith() 方法檢查字串中的 URL。
假設我們的輸入字串是 -
string input = "https://example.com/new.html";
現在我們需要檢查 www 或非 www 連結。為此,在 C# 中使用 if 語句 -
if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) {
}示例
可以嘗試執行以下程式碼來檢查字串中的 URL。
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP