LEN额外空间

时间:2015-12-18 11:08:16

标签: vbscript asp-classic

我有一个我无法弄清楚的问题。我有一个电子表格,其数字格式为文本,我想将其导入SQL数据库。在数据库中,数字前面有一个前导空格,具体取决于长度 例如" 1")," 10"," 100"

所以在我的代码中我检查长度,然后添加适当的空格,但似乎是为了一些未知的原因添加更多,但是如果我打印显示它是正确的数量?

strQuery = "SELECT * FROM [Sheet1$]"
rs.Open strquery, cn

rs.MoveFirst 
if rs.BOF = true and rs.EOF = true then
response.Write "Error:: Products spreadsheet is empty!"
else
while not rs.EOF
response.Write rs.Fields(0) & " " & rs.Fields(1) & "<BR><BR>"
orderno= rs.Fields(0)
lineno = rs.Fields(1)
confirmed= rs.Fields(2)
tracking= rs.Fields(3)
carrier= rs.Fields(4)

if orderno = ""  or isnull(orderno) then
else
orderno = replace(orderno,"'","")
lineno = replace(lineno,"'","")
lineno = trim(lineno)

RESPONSE.WRITE("Start lengh:"&(LEN(lineno)))

if len(lineno=1) then
lineno = "   "&lineno&""
end if

if len(lineno=2) then
lineno = "  "&lineno&""
end if

if len(lineno=3) then
lineno = " "&lineno&""
end if


RESPONSE.WRITE("Mid lengh:"&(LEN(lineno)))
response.write("hello1"&lineno&"hello2")

根据上面的代码,在开始长度打印输出为1,中间长度打印输出为7 - 但我只指定添加3个空格。该值应为4个字符,前面有前导空格。任何帮助非常感谢,真的不明白发生了什么!

1 个答案:

答案 0 :(得分:3)

你刚刚放错了结束括号。

if len(lineno=1) then

应该是:

if len(lineno)=1 then

同样适用于其他检查。

要在HTML中打印多个空格,请为您需要的每个空间使用&nbsp;

相关问题