卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章16505本站已运行3318

C# 程序检查字符串中的 URL

C# 程序检查字符串中的 URL

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语言中,Realloc是什么意思?
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏