Use the StartWith() method in C# to check for URL in a String.
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")) { }
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# 程式檢查字串中的 URL的詳細內容。更多資訊請關注PHP中文網其他相關文章!