【问题标题】:Asp.net multiple replace characters in insert statement?Asp.net 插入语句中的多个替换字符?
【发布时间】:2019-10-04 01:26:24
【问题描述】:

我的 asp.net 网页中有一条 SQL 插入语句,如果 ":" 不存在任何内容"" 如下所示,我必须替换测试框内容

TextBox.Text.Replace(":", "")

有没有办法可以添加一个额外的字符来替换?如果输入到文本框中,我还需要删除“#”。

【问题讨论】:

    标签: sql asp.net vb.net


    【解决方案1】:

    我不知道这些是否可行,但值得一试:

    TextBox.Text.Replace(":", "").Replace("#", "")
    

    或者

    String mytext = TextBox.Text;
    mytext.Replace(":", "");
    mytext.Replace("#", "");
    TextBox.Text = mytext;
    

    【讨论】:

      【解决方案2】:

      如果您可能需要替换更多字符,则值得考虑使用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
      

      输出:

      世界你好!

      【讨论】:

        猜你喜欢
        • 2019-09-03
        • 2019-07-23
        • 1970-01-01
        • 1970-01-01
        • 2013-09-22
        • 2014-06-16
        • 2016-03-01
        • 2019-08-31
        • 1970-01-01
        相关资源
        最近更新 更多