【发布时间】:2019-10-04 01:26:24
【问题描述】:
我的 asp.net 网页中有一条 SQL 插入语句,如果 ":" 不存在任何内容"" 如下所示,我必须替换测试框内容
TextBox.Text.Replace(":", "")
有没有办法可以添加一个额外的字符来替换?如果输入到文本框中,我还需要删除“#”。
【问题讨论】:
我的 asp.net 网页中有一条 SQL 插入语句,如果 ":" 不存在任何内容"" 如下所示,我必须替换测试框内容
TextBox.Text.Replace(":", "")
有没有办法可以添加一个额外的字符来替换?如果输入到文本框中,我还需要删除“#”。
【问题讨论】:
我不知道这些是否可行,但值得一试:
TextBox.Text.Replace(":", "").Replace("#", "")
或者
String mytext = TextBox.Text;
mytext.Replace(":", "");
mytext.Replace("#", "");
TextBox.Text = mytext;
【讨论】:
如果您可能需要替换更多字符,则值得考虑使用regular expression,如下所示:
Imports System.Text.RegularExpressions
Module Program
Sub Main(args As String())
Dim t = "Hello: #World!"
Dim re As New Regex("[#:]")
Dim u = re.Replace(t, "")
Console.WriteLine(u)
End Sub
End Module
输出:
世界你好!
【讨论】: