最近經常見到有人問長英文不自動換行的問題,里面是我寫的一個函數,供大家參考
發表于:2007-06-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) , "<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 : ‘’" + l_strDestString + "‘’")
l_strDestString = replace(l_strDestString , chr(13) + chr(10) , "<br>")
AutoWrap = l_strDestString
end function
原文轉自:http://www.kjueaiud.com