asp中,输出字符串“225533”,要求固定长度为20,不足的用空格补充,超过的截取前面20个字符,如何解决?

来源:百度知道 编辑:UC知道 时间:2024/05/29 19:25:29
你没能看懂我的意思呀,不够20个字符的用这空格补充呀,按你说的代码的话我的那个字符串“225533”输出时后面就没有空格了,如果要输出两个这样的数,它们会紧挨着了,能不能按我的要求做呀,求高手帮忙!!!

function formatStr(str)
dim a,b
b=len(str)
if b<20 then
for i=b to 20
a=a&"&NBSP;" '把&NBSP;换成小写
next
formatStr=str&a
else
formatStr=left(str,20)
end if
end function

for j=1 to 25
s=s&"a"
response.write formatStr(s)
next

<%if len(trim(rs("title")))>20 then
response.write left(trim(rs("title")),20)&"..."
else
response.write trim(rs("title"))
end if
%>

注:title就是你要输出的字段名
20后面的那个...是超出20位的话会显示:前面是20位字符加后面这个... 代表没读完,明白吗?