I have a string with some text and a few line breaks.
How can I count the number of line breaks chr(13) in this string? Any example code?
Printable View
I have a string with some text and a few line breaks.
How can I count the number of line breaks chr(13) in this string? Any example code?
VB Code:
Private Function countCR() dim n as integer val1 = 0 for n = 1 to len("string") if asc(mid("string", n, 1)) = 13 then countCR = countCR + 1 end if next n End Function
Now your problem is going to be you won't have a true "string" with with chr(13). Are you working with a memo field or a text file that you are getting the data from?
This is experimental, fresh out of my brain....
VB Code:
Dim TmpStr$() TmpStr = Split(ThatOneString, Chr(13)) msgbox "There are " & TmpStr().Count - 1 & " Breaks in that thar text!", VBInformation, "Weeee"
Hmmm, tested it, maybe not lol....
Has more errors than one could want.. I will see what I can do.
Ok, this works too...
VB Code:
Private Sub Command2_Click() Dim TmpStr$() TmpStr = Split(Text1.Text, Chr(13)) MsgBox "There are " & UBound(TmpStr()) & " Breaks in that thar text!", vbInformation, "Weeee" End Sub
:D :D :D :D :D :D :D
Thanks very much for that guys - much appreciated :)
Very Welcome.
:D:D:D:D:D:D:D