在写新版块的时候,碰到一个小问题,新闻是生成静态HTML的,表NEWS中的CONTENT是新闻的内容,在前台,显示图片新闻的同时,要显示一些新闻内容的简介,CONTENT 字段里面有许多的标记符或其他符号,
为此,特写了个小函数实现
-- =============================================
-- Author: <Author,OldA>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
ALTER function [dbo].[fn_GetChinese] (@str varchar(4000))
returns varchar(100)
as
begin
declare @i int ,@itmp int
select @i=1
while @i<=len(@str)
begin
select @itmp=convert(int,substring(convert(varbinary,substring(@str,@i,1)),1,1))
if @itmp>127
begin
break
end
select @i=@i+1
end
select @str=substring(@str,@i,100)
select @itmp=charindex('<',@str)
if @itmp>0
begin
select @str=substring(@str,0,@itmp)
end
return @str
end
。。。。。。。。由于项目时间的仓促,并没做过多的测试,希望看官在性能上或其他方面,提点意见!