请问SQL Server中如何将非法字符检测出来处理掉,或者如何在ADO Dataset的SaveToFile生成的xml中自动除去这些无效字符?比如包含ASCII码值为0x1C、0x0C……等的数据,例如'4 '4后面就有一个0x1C,不是空格!
相关贴http://community.csdn.net/Expert/topic/3337/3337248.xml?temp=.2155878
-------------------------------------------------------------------
非法字符的判断规则:字符编码小于32,但不包括回车/换行/TAB
--------------------------------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_replace]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_replace]
GO
/*--非法字符替换函数
去掉字符串中,小于32的字符
保留 TAB char(9)
换行 char(10)
回车 char(13)
--邹建 2004.09(引用请保留此信息)--*/
/*--调用示例
--调用函数进行替换处理的示例
declare @s varchar(10)
set @s='a '+'b'+char(11)+'c'
select dbo.f_replace(@s)
--*/
create function f_replace(
@str varchar(8000)
)returns varchar(8000)
as
begin
select @str=replace(@str,a,'')
from(select a=N''
union all select N'' union all select N''
union all select N'' union all select N''
union all select N'' union all select N''
union all select N''
-- union all select N' ' --TAB char(9)
-- union all select N'
-- ' --换行 char(10)
union all select N' ' union all select N' '
-- union all select N'
-- ' --回车 char(13)
union all select N'' union all select N''
union all select N'' union all select N''
union all select N'' union all select N''
union all select N'' union all select N''
union all select N'' union all select N''
union all select N'' union all select N''
union all select N'' union all select N''
union all select N' ' union all select N' '
union all select N' ' union all select N' '
)a where charindex(a,@str)>0
return(@str)
end
go