使用 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