Displaying Source Code(s)
|
|
Breakup sentences longer than x Characters
--------------------------------------------------------------------------------
function mBreakupWordsLongerThanMax(byval vstrSentence, byval
vlngMaxWordLength)
Dim lngIndex,strNextWord,strOutput
Dim arrWords
lngIndex=0
'get words into array
arrWords=split(vstrSentence," ")
'go through words
strOutput=""
'Response.Write "UBound(arrWords)" & UBo
'
' und(arrWords)
For lngIndex = 0 To UBound(arrWords)
strNextWord=arrWords(lngIndex)
'check if > max
if len(strNextWord > vlngMaxWordLength) Then
'> max
strOutput=strOutput & mSplitWord(strNextWord,vlngMaxWordLength)
Else
'<= max
strOutput=strOutput & strNextWord
End if
Next
'set return
if right(strOutput,1)=" " Then
'get rid of rightmost space
mBreakupWordsLongerThanMax=mid(strOutput,1,len(strOutput)-1)
Else
'return all
mBreakupWordsLongerThanMax=strOutput
End if
End function
function mSplitWord(byval vstrWord, _
byval vlngLength)
'*********************************
'purpose:split word
'inputs: vstrWord--word to split
' vlngLength--length to split at
'*********************************
Dim strOutput,lngIndex
strOutput=""
For lngIndex = 1 To len(vstrWord) step vlngLength
strOutput=strOutput & _
" " & mid(vstrWord,lngIndex,vlngLength)
Next
'set return
mSplitWord= mid(strOutput,2) & " "
End function |
|
|