Parsing info from string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a comment field called: Item.userproperties("CommentBar").valu
What I would like to do is check every 140 characters to make sure it's a blank and if so insert a chr(13) and do this till the end of the string

Does anyone have any sample code on how to do this?

Example: "this is a test OF a test for a test to see if this works.

it scans the string 140 characters ( i know it's not 140 in the example) and comes to the word 'of'
the F is 140 so if it's not blank moves up 1 more character till it's blank and then puts chr(13) in

Output: this is a test of chr(13) a test to see if this chr(13) works
 
How about something like this:
Sub Experiment()
Dim str, str1, strChar As String
Dim intLength, i, intLineStart, intLineEnd As Integer
str = Item.userproperties("CommentBar").Value
intLineStart = 1
intLineEnd = 40
intLength = Len(str)
If intLength > intLineEnd Then
Do While intLength > intLineEnd
str1 = str1 & Mid(str, intLineStart, intLineEnd -
1)
For i = intLineEnd To intLength
strChar = Mid(str, i, 1)
If strChar = " " Then
str1 = str1 & vbNewLine
intLineEnd = i + 40
intLineStart = i + 1
Exit For
Else
str1 = str1 & strChar
End If
Next i
Loop
str1 = str1 & Right(str, intLength - intLineStart + 1)
Else
str1 = str
End If
Debug.Print str1

End Sub
-----Original Message-----
I have a comment field called: Item.userproperties ("CommentBar").value
What I would like to do is check every 140 characters to
make sure it's a blank and if so insert a chr(13) and do
this till the end of the string.
Does anyone have any sample code on how to do this??

Example: "this is a test OF a test for a test to see if this works."

it scans the string 140 characters ( i know it's not 140
in the example) and comes to the word 'of'.
the F is 140 so if it's not blank moves up 1 more
character till it's blank and then puts chr(13) in.
 
Back
Top