Results 1 to 3 of 3
  1. #1
    tnt is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    2

    CRLF automatically appended in string concat?

    Why does this FN return 2 in immediate window?

    ?CountOccurrencesOfSubStrInBigStr("asdf,qwer,erty, " & Chr$(13) & Chr$(10) & "drgth,fgsda,wetq",Chr$(13) & Chr$(10))


    2


    Function CountOccurrencesOfSubStrInBigStr(BigString As String, SubString As String) As Integer
    CountOccurrencesOfSubStrInBigStr = Len(BigString) - Len(Replace(BigString, SubString, ""))

    End Function

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    BigString is 34 characters, including the two characters for Chr$(13) & Chr$(10)

    SubString is 2 characters, the Chr$(13) & Chr$(10)

    You replace the 2 characters with empty string, resulting in 32 character string.

    34 - 32 = 2
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by tnt View Post
    Why does this FN return 2 in immediate window?

    ?CountOccurrencesOfSubStrInBigStr("asdf,qwer,erty, " & Chr$(13) & Chr$(10) & "drgth,fgsda,wetq",Chr$(13) & Chr$(10))
    2


    Function CountOccurrencesOfSubStrInBigStr(BigString As String, SubString As String) As Integer
    CountOccurrencesOfSubStrInBigStr = Len(BigString) - Len(Replace(BigString, SubString, ""))

    End Function

    Because that is the result of your function.

    Chr$(13) = (CR) = carriage return (1 character)
    Chr$(10) = (LF) = line feed (1 character)

    So if you count the length of "BigString", including the space, CR & LF, you get 34.
    Then you replace CR & LF (length of 2) with "" (Nothing, a length of 0). Now the length of "BigString" is 32.
    When you subtract the two lengths, 34 - 32, you get 2.

    If you want to count the occurrences,look at this site:

    www.freevbcode.com

    Count the Number of Occurrences of a Character Sequence in a String

    http://www.freevbcode.com/ShowCode.a...025&NoBox=True

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Concat field names in Update SQL
    By Deutz in forum Queries
    Replies: 8
    Last Post: 09-21-2011, 05:43 PM
  2. SQL + VBA String
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 08-22-2011, 08:44 AM
  3. Group concat
    By iostream in forum Queries
    Replies: 1
    Last Post: 02-23-2011, 12:29 PM
  4. Concat in SQL creates unwanted spaces
    By Deutz in forum Access
    Replies: 3
    Last Post: 12-07-2010, 11:43 PM
  5. concat problem
    By leahcim_32 in forum Access
    Replies: 1
    Last Post: 08-28-2009, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums