Results 1 to 7 of 7

Thread: String - counting the number of line breaks CHR(13)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    New Zealand
    Posts
    78

    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?

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Location
    San Diego, CA
    Posts
    159
    VB Code:
    1. Private Function countCR()
    2. dim n  as integer
    3.      val1 = 0
    4.      for n = 1 to len("string")
    5.           if asc(mid("string", n, 1)) = 13 then
    6.                countCR = countCR + 1
    7.           end if
    8.      next n
    9. 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?
    ttfn
    Kicker

  3. #3
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    This is experimental, fresh out of my brain....

    VB Code:
    1. Dim TmpStr$()
    2.  
    3.     TmpStr = Split(ThatOneString, Chr(13))
    4.     msgbox "There are " & TmpStr().Count - 1 & " Breaks in that thar text!", VBInformation, "Weeee"

  4. #4
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Hmmm, tested it, maybe not lol....

    Has more errors than one could want.. I will see what I can do.

  5. #5
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Ok, this works too...

    VB Code:
    1. Private Sub Command2_Click()
    2. Dim TmpStr$()
    3.     TmpStr = Split(Text1.Text, Chr(13))
    4.             MsgBox "There are " & UBound(TmpStr()) & " Breaks in that thar text!", vbInformation, "Weeee"
    5. End Sub


  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    New Zealand
    Posts
    78
    Thanks very much for that guys - much appreciated

  7. #7
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Very Welcome.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width