×

Loading...
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!

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.
        • 很有价值,多谢!