学院首页>网络编程>ASP>长英文不自动换行的原因及解决方法

长英文不自动换行的原因及解决方法

作者:bigeagle 来源:未知 添加时间:2006-5-21 10:28:30
一段没有空格的长英文,系统会认为它是一个单词,为了保持单词的完整性不会自动换行。其实这种情况不处理也可以,因为在实际应用中除了测试或有人捣乱不会出现这种情况,不过为了以防万一吧,我几个月前写了下面这个函数,只是一种权宜之计,为了对付恶意破坏者。
 '-------------------------------------------------
'
'  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
站内搜索