半角与全角之间的转换

时间:2014-03-05 06:29:45   收藏:0   阅读:328

ALTER   function   [dbo].[u_convert]( 
@str   nvarchar(4000),   --要转换的字符串 
@flag   bit              --转换标志,0转换成半角,1转换成全角 
)
returns   nvarchar(4000) 
AS 
begin 
    declare  
          @pat nvarchar(8),
          @step   int,
          @i   int,
          @spc   int 
    if  @flag=0
     begin
       select   @pat=N‘%[!-~]%‘,@step=-65248, 
       @str=replace(@str,N‘ ‘,N‘   ‘) 
     end
    else 
     begin
       select   @pat=N‘%[!-~]%‘,@step=65248, 
       @str=replace(@str,N‘   ‘,N‘ ‘) 
     end
    set   @i=patindex(@pat   collate LATIN1_GENERAL_BIN,@str) 
    while   @i>0 
       select   @str=replace(@str, 
    substring(
               @str,@i,1),
               nchar(unicode(substring(@str,@i,1))+@step)),
               @i=patindex(@pat   collate   LATIN1_GENERAL_BIN,@str) 
     return(@str) 
end

半角与全角之间的转换,布布扣,bubuko.com

原文:http://www.cnblogs.com/yclnet/p/3580648.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!