我不确定您的 7 个字符限制是如何应用的,但是对于一般方法,以下将满足您对任何长度字符串的需求:
function AddFontTag(byval str)
AddFontTag = Empty
do while len(str) <> 0
' get next character
dim c: c = left(str, 1)
' reduce original string
str = right(str, len(str) - 1)
' build up output string
AddFontTag = AddFontTag & "<font>" & c & "</font>"
loop
end function
这个例子
dim test: test = AddFontTag("a test")
Response.Write test
会给你
<font>a</font><font> </font><font>t</font><font>e</font><font>s</font><font>t</font>
如果您只想将此应用于长度小于 7 的字符串,则可以添加
if len(str) > 6 then
exit function
end if
在while循环之前或
str = left(str, 6)
如果您只想将其应用于任何长度字符串的前 6 个字符