繁体中文
设为首页
加入收藏
当前位置:ASP技术首页 >> ASP基础 >> 最近经常见到有人问长英文不自动换行的问题,里面是我写的一个函数,供大家参考

最近经常见到有人问长英文不自动换行的问题,里面是我写的一个函数,供大家参考

2006-07-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:一段没有空格的长英文,系统会认为它是一个单词,为了保持单词的完整性不会自动换行。其实这种情况不处理也可以,因为在实际应用中除了测试或有人捣乱不会出现这种情况,不过为了以防万一吧,我几个月前写了下面...

一段没有空格的长英文,系统会认为它是一个单词,为了保持单词的完整性不会自动换行。其实这种情况不处理也可以,因为在实际应用中除了测试或有人捣乱不会出现这种情况,不过为了以防万一吧,我几个月前写了下面这个函数,只是一种权宜之计,为了对付恶意破坏者。

'-------------------------------------------------

'

' function name: autowrap

'

'

' description : 解决长英文不自动换行的问题

'

' parameters : a_strSourceString :要转换的源字符串

'

' a_intSize , 每行宽度

'

' author: bigeagle

'

' date : 2000/4/17

'

' history: 2000/4/17 : version 1.0

'

'-------------------------------------------------------

function AutoWrap(a_strSourceString , a_intSize)

dim l_strDestString

'如果内容中有回车则退出

'if instr(a_strSourceString , chr(13) + chr(10) ) <> 0 then

' AutoWrap = replace(a_strSourceString , chr(13) + chr(10) , "
")

' exit function

'end if

'check if valid parameters

call assert(vartype(a_strSourceString) = 8 , "AutoWrap" , "a_strSourceString must be a string")

call assert(vartype(a_intSize) = 2 , "AutoWrap" , "a_intSize must be a integer")

dim i

if a_intSize >= len(a_strSourceString) then

l_strDestString = a_strSourceString

else

' l_strDestString = left(a_strSourceString , a_intSize)

for i = 1 to len(a_strSourceString) step a_intSize

if instr( i , mid(a_strSourceString , i , a_intSize) , chr(32) ) = 0 _

or instr( i , mid(a_strSourceString , i , a_intSize) , chr(13)+chr(10) )then

l_strDestString = l_strDestString + " " + mid (a_strSourceString , i + 1 , a_intSize)

else

l_strDestString = l_strDestString + mid(a_strSourceString , i + 1 , a_intSize)

end if

next

end if

call print("[AutoWrap:]return value is : '" + l_strDestString + "'")

l_strDestString = replace(l_strDestString , chr(13) + chr(10) , "
")

AutoWrap = l_strDestString

end function

责任编辑:admin
相关文章