×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Good news and bad news

The bad news is there isn’t any built-in function in SQL server to conduct regular expression.

The good news is still you can do it.

In SQL server 2005, you can create stored procedures and user-defined function by managed code and CLR Integration. Of course, regular expressions can be done exactly same as codes we showed.

In SQL server 2000, ECMA Regex can be used via VBScript.RegExp. You can google VBScript.RegExp to get sql code creating regular expression User-defined functions.
Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / 请问如何用C#削掉多余的逗号.比如ABC,,,,,DEF,如何变成ABC,DEF.多谢!
    • split then join, when split, set the second arg to remove null value. post ur code after done, i want to know how. thanks
      • string.Join(",", inputString.Split(new char[]{','}, System.StringSplitOptions.RemoveEmptyEntries)); this works, dont know if regular expression is faster
    • Replace(",,",",") until length is not changed.
    • regular expression可以轻松搞定。
      • show me how, thanks
        • Regex rg = new Regex(@"[\,]{2,}"); OutputTxt.Text = rg.Replace(InputTxt.Text, ",");
          • thanks, regular expression looks much clean
          • whats the difference between u and downstair?
            • i have no idea,not my majia.
              • i mean the code, not id, know little about regular expression, so could not figure out the diff
                • no difference, just different expression but same meaning
    • Regex reg = new Regex(",{2,}"); string strNew = reg.Replace(str, ",");
      • Regex reg = new Regex(",+"); ---- I think this is more suitable to generate REG rule
        • Although in this case ",+" and ",{2,}" will have same result, (because replacing "," to "," doesn’t affect anything), in other circumstances there is difference. ",+" matches ",", ",,", or more. ",{2,}" matches ",,", or more.
    • 多谢诸位.看来真是piece of cake.
    • 再多问一句,在TRANSACT SQL 里,是否也有相应的办法?再谢!
      • Good news and bad news
        The bad news is there isn’t any built-in function in SQL server to conduct regular expression.

        The good news is still you can do it.

        In SQL server 2005, you can create stored procedures and user-defined function by managed code and CLR Integration. Of course, regular expressions can be done exactly same as codes we showed.

        In SQL server 2000, ECMA Regex can be used via VBScript.RegExp. You can google VBScript.RegExp to get sql code creating regular expression User-defined functions.
        • 很有价值,多谢!