zoukankan      html  css  js  c++  java
  • 去除字符串中连续的分割符 枫

    --创建函数

    create function [dbo].[m_delrepeatsplit]

    (

        @str varchar(2000),

        @split nvarchar(200)

    )

    returns nvarchar(2000)

    as  

    begin

        --begin declare   

           declare @count int,@i int,@isnull int

           declare @newchar nvarchar(200),@nn nvarchar(300)

           set @count=len(@str);set @i=1;set @isnull=1;set @nn='';

        --end declare

        --begin while

           while @i<@count+1

           begin

               set @newchar=substring(@str,@i,1)

               if(@isnull=1)

               begin

                  set @nn=@nn+@newchar;   

                  if(@newchar=@split)

                      begin

                         set @isnull=0;

                      end

                  else

                      begin

                         set @isnull=1;

                      end   

               end

               else

                  begin

                      if(@newchar=@split)

                         begin

                             set @isnull=0;

                         end

                      else

                         begin

                             set @nn=@nn+@newchar;   

                             set @isnull=1;

                         end   

                  end

               set @i=@i+1;

           end

        --end while

        return  @nn

    end

     

    --2、测试示例

    declare @str nvarchar(200)

    set @str='1  2 3    4 555 6  7    7';

    declare @split nvarchar(200)

    set @split=' ';

    select dbo.m_delrepeatsplit(@str,@split) as newchar

     

    --3、运行结果

    /*

    newchar

    ------------------

    1 2 3 4 555 6 7 7

    */

  • 相关阅读:
    Clipper库中文文档详解
    JavaScript-Clipper.js
    安装Scrapy遇到的问题
    Python中if __name__ == '__main__'的使用
    写出一段Python代码实现删除一个list里面的重复元素
    Python 内置函数(反射类)
    Python 内置函数(集合操作,IO操作)
    Python 内置函数(数学运算类,逻辑判断类)
    Python 推导式(列表推导式,字典推导式,集合推导式)
    Python 闭包和装饰器
  • 原文地址:https://www.cnblogs.com/mrray/p/1992320.html
Copyright © 2011-2022 走看看