【叶子函数分享二】去除字符串中连续的分割符
来源:互联网 发布:python 卷积函数 编辑:程序博客网 时间:2024/05/28 03:02
--创建函数
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
*/
特别说明:
如果数据量比较大,尽量避免使用自定义函数,以免严重影响性能。
- 【叶子函数分享二】去除字符串中连续的分割符
- 【叶子函数分享二】去除字符串中连续的分割符
- 去除字符串中连续的分割符
- 【SQL分享】去除字符串中连续的分隔符【经典】
- 【叶子函数分享二十五】从第一个汉字开始分割字符串
- 【叶子函数分享二十五】从第一个汉字开始分割字符串
- 【叶子函数分享二十六】过滤掉字符串中重复的字符
- 【叶子函数分享三十七】求字符串中汉字的个数
- 【叶子函数分享九】根据字符分割字符串的三种写法
- 【叶子函数分享九】根据字符分割字符串的三种写法
- 【叶子函数分享六】求两个字符串中相同的汉字及字母的个数
- 【叶子函数分享六】求两个字符串中相同的汉字及字母的个数
- 【叶子函数分享一】去除字符串中的html标记及标记中的内容
- 【叶子函数分享一】去除字符串中的html标记及标记中的内容
- 【叶子函数分享三】求第一个字符串中第二个串的个数
- 【叶子函数分享三】求第一个字符串中第二个串的个数
- VC 分割字符串以及去除路径中不合法的字符
- python 去除字符串中连续的空格,并使用其他的分隔符替代连续的空格
- hdu 1106 排序
- js 运行本地程序 new activeXobjext('wscript.shell').run(command,1,true)
- 算法数据结构试题——在数组中找出已知和的组成数
- Serializable
- 红外遥控系统之一:硬件和协议基础
- 【叶子函数分享二】去除字符串中连续的分割符
- Activity SDK文档
- 【叶子函数分享三】求第一个字符串中第二个串的个数
- zoj1438_三维迷宫
- Activity SDK文档
- Servlet
- 【叶子函数分享四】综合模糊查询
- Flex 学习站点汇总
- Activity SDK文档