日期:2012-12-21  浏览次数:20817 次

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