Using Visual Basic to word wrap :
Function WordWrap$ (St$, Length)
'-- This function converts raw text into CRLF delimited lines.
Length = Length + 1
St$ = Trim$(St$)
Cr$ = Chr$(13)
Crlf$ = Chr$(13) & Chr$(10)
Do
L = Len(NextLine$)
S = InStr(St$, " ")
C = InStr(St$, Cr$)
If C Then
If L + C <= Length Then
Text$ = Text$ & NextLine$ & Left$(St$, C)
NextLine$ = ""
St$ = Mid$(St$, C + 1)
GoTo LoopHere
End If
End If
If S Then
If L + S <= Length Then
DoneOnce = True
NextLine$ = NextLine$ & Left$(St$, S)
St$ = Mid$(St$, S + 1)
ElseIf S > Length Then
Text$ = Text$ & Crlf$ & Left$(St$, Length)
St$ = Mid$(St$, Length + 1)
Else
Text$ = Text$ & NextLine$ & Crlf$
NextLine$ = ""
End If
Else
If L Then
If L + Len(St$) > Length Then
Text$ = Text$ & NextLine$ & Crlf$ & St$ & Crlf$
Else
Text$ = Text$ & NextLine$ & St$ & Crlf$
End If
Else
Text$ = Text$ & St$ & Crlf$
End If
Exit Do
End If
LoopHere:
Loop
WordWrap$ = Text$
End Function
Function WordWrap$ (St$, Length)
'-- This function converts raw text into CRLF delimited lines.
Length = Length + 1
St$ = Trim$(St$)
Cr$ = Chr$(13)
Crlf$ = Chr$(13) & Chr$(10)
Do
L = Len(NextLine$)
S = InStr(St$, " ")
C = InStr(St$, Cr$)
If C Then
If L + C <= Length Then
Text$ = Text$ & NextLine$ & Left$(St$, C)
NextLine$ = ""
St$ = Mid$(St$, C + 1)
GoTo LoopHere
End If
End If
If S Then
If L + S <= Length Then
DoneOnce = True
NextLine$ = NextLine$ & Left$(St$, S)
St$ = Mid$(St$, S + 1)
ElseIf S > Length Then
Text$ = Text$ & Crlf$ & Left$(St$, Length)
St$ = Mid$(St$, Length + 1)
Else
Text$ = Text$ & NextLine$ & Crlf$
NextLine$ = ""
End If
Else
If L Then
If L + Len(St$) > Length Then
Text$ = Text$ & NextLine$ & Crlf$ & St$ & Crlf$
Else
Text$ = Text$ & NextLine$ & St$ & Crlf$
End If
Else
Text$ = Text$ & St$ & Crlf$
End If
Exit Do
End If
LoopHere:
Loop
WordWrap$ = Text$
End Function
Function to replace string :
Public Function ReplaceString(ByVal pString As String, ByVal Keyword As String, ByVal NewKeyWord As String) As String
Dim StrLen As Integer
Dim StrOut As String
Dim KeyPos As Integer
Dim StrLenChange As Boolean
Dim StartPos As Integer
' set a few values before we go any further
StartPos = 1
StrLen = Len(pString)
' if the word to replace and the word to replace by are different lengths, record that they are
If Len(Keyword) <> Len(NewKeyWord) Then StrLenChange = True
' check to see where the first occurence of the keyword to replace is in the string
KeyPos = InStr(StartPos, pString, Keyword)
' only do the replace loop if the keyword string is there
While KeyPos > 0
' rebuild the string, taking out the keyword and replacing it with the NewKeyword
pString = Left(pString, KeyPos - 1) & NewKeyWord & Mid(pString, KeyPos + Len(Keyword), StrLen - KeyPos - Len(Keyword) + 1)
' if the Keyword and NewKeyword as different lengths then recalc the length of the string
If StrLenChange Then StrLen = Len(pString)
' calculate the position where we should start looking to see if the KeyWord is in the string
StartPos = KeyPos + Len(NewKeyWord)
' check to see where the next occurence of the keyword to replace is in the string
KeyPos = InStr(StartPos, pString, Keyword)
Wend
' return the string
ReplaceString = pString
End Function
Public Function ReplaceString(ByVal pString As String, ByVal Keyword As String, ByVal NewKeyWord As String) As String
Dim StrLen As Integer
Dim StrOut As String
Dim KeyPos As Integer
Dim StrLenChange As Boolean
Dim StartPos As Integer
' set a few values before we go any further
StartPos = 1
StrLen = Len(pString)
' if the word to replace and the word to replace by are different lengths, record that they are
If Len(Keyword) <> Len(NewKeyWord) Then StrLenChange = True
' check to see where the first occurence of the keyword to replace is in the string
KeyPos = InStr(StartPos, pString, Keyword)
' only do the replace loop if the keyword string is there
While KeyPos > 0
' rebuild the string, taking out the keyword and replacing it with the NewKeyword
pString = Left(pString, KeyPos - 1) & NewKeyWord & Mid(pString, KeyPos + Len(Keyword), StrLen - KeyPos - Len(Keyword) + 1)
' if the Keyword and NewKeyword as different lengths then recalc the length of the string
If StrLenChange Then StrLen = Len(pString)
' calculate the position where we should start looking to see if the KeyWord is in the string
StartPos = KeyPos + Len(NewKeyWord)
' check to see where the next occurence of the keyword to replace is in the string
KeyPos = InStr(StartPos, pString, Keyword)
Wend
' return the string
ReplaceString = pString
End Function
This code is using to parse string :
Private Sub cmdParse_Click()
Dim colWords As Collection
Dim lngWordCount As Long
Dim lngCounter As Long
lstResults.Clear
Set colWords = ParseString(txtParse.Text)
lngWordCount = colWords.Count
For lngCounter = 1 To lngWordCount
lstResults.AddItem colWords.Item(lngCounter).Value
DoEvents
Next lngCounter
Set colWords = Nothing
End Sub
Private Sub cmdParse_Click()
Dim colWords As Collection
Dim lngWordCount As Long
Dim lngCounter As Long
lstResults.Clear
Set colWords = ParseString(txtParse.Text)
lngWordCount = colWords.Count
For lngCounter = 1 To lngWordCount
lstResults.AddItem colWords.Item(lngCounter).Value
DoEvents
Next lngCounter
Set colWords = Nothing
End Sub
