|
-
Apr 14th, 2003, 11:43 PM
#1
Thread Starter
Lively Member
String - counting the number of line breaks CHR(13)
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?
-
Apr 14th, 2003, 11:53 PM
#2
Addicted Member
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?
-
Apr 14th, 2003, 11:58 PM
#3
Frenzied Member
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"
-
Apr 15th, 2003, 12:01 AM
#4
Frenzied Member
Hmmm, tested it, maybe not lol....
Has more errors than one could want.. I will see what I can do.
-
Apr 15th, 2003, 12:07 AM
#5
Frenzied Member
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
-
Apr 15th, 2003, 04:23 PM
#6
Thread Starter
Lively Member
Thanks very much for that guys - much appreciated
-
Apr 15th, 2003, 06:20 PM
#7
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|