检查字符串中的 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