使用 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
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP