我试过这么做
using System;
using System.Collections.Generic;
using System.Text;
namespace UrlsDetector
{
class UrlDetector
{
public static string RemoveUrl(string input)
{
var words = input;
while(words.Contains("https://"))
{
string urlToRemove = words.Substring("https://", @" ");
words = words.Replace("https://" + urlToRemove , @"");
}
}
}
class Program
{
static void Main()
{
Console.WriteLine(UrlDetector.RemoveUrl(
"I saw a cat and a horse on https://www.youtube.com/"));
}
}
}
但它不起作用
我想要实现的是删除整个"https://www.youtube.com/并显示"我看见一只cat 和一匹马"
如果句子没有url,我还想显示类似"您输入的句子没有url"的消息.但正如你所能做的那样,我并没有为此编写任何代码,我只需要先修复这些代码,但如果你也想帮我这么做,我很高兴地感谢你.
感谢您的回复.