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"),当它应该只是链接,然后是标签,它们之间没有空格。

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

不是 100% 确定我遵循,但如果你要;

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

你会看到一个空间; AAA BBB因为HTMLDecode做的第一件事是在输入字符串前面加上回车/换行符和制表符,浏览器将其显示为空格。

如果您不希望看到可见空间,请删除sText = vbcrlf & vbtab & sText

(另外,输入在HTMLDecode后不会被修剪,所以如果它被传递"XXX&nbsp;",你会有一个尾随空格)

最新更新