学习网考试学习资料

Gzu521.com

解决长英文不自动换行的函数

ASP教程   点击:次   发布时间:2004-1-30   【字体: 】   来源:
贵 州 学 习 网
[ 关键字 ] asp,换行,解决

一段没有空格的长英文,系统会认为它是一个单词,为了保持单词的完整性不会自动换行。
其实这种情况不处理也可以,因为在实际应用中除了测试或有人捣乱不会出现这种情况,不过为了以防万一吧,我几个月前写了下面这个函数,只是一种权宜之计,为了对付恶意破坏者。
’-------------------------------------------------
’ function name: autowrap
’ description : 解决长英文不自动换行的问题
’ parameters : txt :要转换的源字符串
’ candu , 每行宽度
’-------------------------------------------------------
function autowrap(txt , candu)
dim bha
’如果内容中有回车则退出
’if instr(txt , chr(13) + chr(10) ) <> 0 then
’ autowrap = replace(txt , chr(13) + chr(10) , "
")
’ exit function
’end if
call assert(vartype(txt) = 8 , "autowrap" , "txt must be a string")
call assert(vartype(candu) = 2 , "autowrap" , "candu must be a integer")
dim i
if candu >= len(txt) then
bha = txt
else
’bha = left(txt , candu)
for i = 1 to len(txt) step candu
if instr(i,mid(txt,i,candu) , chr(32) ) = 0 _
or instr( i , mid(txt , i , candu) , chr(13)+chr(10) )then
bha = bha + " " + mid (txt , i + 1 , candu)
else
bha = bha + mid(txt , i + 1 , candu)
end if
next
end if
call print("[autowrap:]return value is : ’" + bha + "’")
bha = replace(bha , chr(13) + chr(10) , "
")
autowrap = bha
end function

本方法在本站的老站点上使用。反映良好。

责任编辑:gzu521

网络编程分类
ASP教程
.Net教程
Java教程
PHP教程
数据库基础
ACCESS教程
SQL Server教程
MySQL教程
Oracle教程
分类推荐信息
更多...
大类最新文章
更多...