當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

最近經經常見到有人問長英文不自動換行的問題,里面是我寫的一個函數,供大家參考

最近經經常見到有人問長英文不自動換行的問題,里面是我寫的一個函數,供大家參考

更新時間:2019-06-23 文章作者:未知 信息來源:網絡 閱讀次數:

一段沒有空格的長英文,系統會認為它是一個單詞,為了保持單詞的完整性不會自動換行。其實這種情況不處理也可以,因為在實際應用中除了測試或有人搗亂不會出現這種情況,不過為了以防萬一吧,我幾個月前寫了下面這個函數,只是一種權宜之計,為了對付惡意破壞者。
'-------------------------------------------------
'
'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

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
亚洲嫩草影院久久精品