【发布时间】:2021-03-26 02:27:25
【问题描述】:
我正在尝试实施一种解决方案,以从文本框中删除 URL 并将其替换为“”
所以是这样的:
“嘿,看看这个网站 http://www.anywhere.com”
会变成:
“嘿,看看这个网站
”
这是我目前所拥有的,但我认为我做的不正确,任何帮助将不胜感激! :)
private void btnFilter_Click(object sender, RoutedEventArgs e)
{
if (txtContent.Text.Contains("http:"))
{
txtContent.Text.Replace("http", "<URL Quarrantined>");
}
}
【问题讨论】:
-
设置修改文本 txtContent.Text = txtContent.Text.Replace("http", "
"); -
与其他一些编程语言相比,C#字符串替换不会修改原字符串,而是保持原字符串不变,并将修改后的字符串作为返回值。
标签: c# .net string wpf replace