这个功能是否有空间?

时间:2011-04-06 15:31:49

标签: function asp-classic

我们有一个网站,它有许多由我们的第三方程序员编写的有用功能,但最近,我注意到其中一个似乎在运行时放入一个空格,但我似乎无法找到可能的位置以便将其删除。

该函数称为“formatspecialcharacters”。它的功能是获取一个字符串并查看它以将特殊字符从字符串更改为HTML实体,并写成:

function formatspecialcharacters(stringtoformat)

formatspecialcharacters = ""

if isblank(stringtoformat) then exit function

stringtoformat = CStr(stringtoformat)
stringtoformat = Trim(stringtoformat)
fieldcontents = HTMLDecode(stringtoformat)

if Len(fieldcontents)>0 then
    for character_i = 1 to Len(fieldcontents)
        character_c = asc(mid(fieldcontents, character_i, 1))

        select case character_c
        case 174, 169 
            formatspecialcharacters = formatspecialcharacters & "<sup>" & chr(character_c) & "</sup>"
        case else
            formatspecialcharacters = formatspecialcharacters & chr(character_c)
        end select
    next
end if
end function

在上面的一个内部运行的另一个函数(HTMLDecode)写成:

Function HTMLDecode(sText)
sText = vbcrlf & vbtab & sText
    Dim I
    sText = Replace(sText, "&quot;", Chr(34))
    sText = Replace(sText, "&lt;"  , Chr(60))
    sText = Replace(sText, "&gt;"  , Chr(62))
    sText = Replace(sText, Chr(62)  , Chr(62) & vbcrlf & vbtab)
    sText = Replace(sText, "&amp;" , Chr(38))
    sText = Replace(sText, "&nbsp;", Chr(32))
    sText = Replace(sText, Chr(147), Chr(34)) 'smart quotes to proper quotes
    sText = Replace(sText, Chr(148), Chr(34))
    sText = Replace(sText, Chr(146), Chr(39)) 'smart apostrophe to proper apostrophe
    For I = 1 to 255
        sText = Replace(sText, "&#" & I & ";", Chr(I))
    Next
    HTMLDecode = sText
End Function

我认为它可能在第二个功能中,因为当我像这样使用它时:

<a href="<%=decendentdocumentformat_filename(j)%>"><%=formatspecialcharacters(decendentdocumentformat_label(j))%></a>

"decendentdocumentformat_filename(j)" = "/example.html""formatspecialcharacters(decendentdocumentformat_label(j))" = "Web Page"

的位置

在这个例子中,当它被渲染时,我有链接,然后是一个空格,然后是标签(在这种情况下,"Web Page")当它应该是链接然后标签之间没有空格

任何帮助都会很棒 提前谢谢。

1 个答案:

答案 0 :(得分:4)

不是100%肯定我会关注,但如果你愿意的话;

<p><%=formatspecialcharacters("AAA") %><%=formatspecialcharacters("BBB") %></p>

你会看到一个空间; AAA BBB,因为第一件事HTMLDecode所做的是提前一个回车/换行&amp; tab到输入字符串,浏览器显示为空格。

如果您不希望可见空格删除sText = vbcrlf & vbtab & sText

(另外,HTMLDecode之后没有修剪输入,所以如果它被传递“XXX&nbsp;”你会有一个尾随空格