C#

在字串左(或右)加空格或指定char字符,使字串达到指定长度,如: 
string str1="你好"; 
str1=str1.PadLeft(6,'3'); //无第二参数为加空格 
Response.Write(str1); //结果为“3333你好” , 字串长为6 

 

sql

方法1:

declare 
@a nvarchar(50),
@b nvarchar(50)
set @a = 'abcasdf'
set @b = 'ab'
select @a + space(20 - len(@a))
select @b + space(20 - len(@b))

 

注:space ( 参数>=0 ),        补的空格数, 不能超过字符数,下同

 

方法2:

declare 
@aa nvarchar(200)
set @aa = 'sgawe'

select @aa + replicate(' ', 40 - datalength(@aa))

posted on 2014-07-01 15:58  清风暮雨  阅读(6822)  评论(0编辑  收藏  举报