CountInstance() was a beautiful contribution by Doug Steele a few years back...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MLH

    CountInstance() was a beautiful contribution by Doug Steele a few years back...

    Douglas j.Steele contributed Wed, Aug 11 2004 6:15 pm.
    Replace$ is not available in A97. Chuck Grimsby took care
    of that with his airing of the JoeReplace FN.

    My Q here today is to Doug, in regard to the use of the backslash...

    Is there ever an instance where
    CountInstances = (Len(ToSearch) - Len(JoeReplace( ToSearch, ToFind,
    vbNullString))) \ Len(ToFind)

    would return a value different than
    CountInstances = (Len(ToSearch) - Len(JoeReplace( ToSearch, ToFind,
    vbNullString))) / Len(ToFind)
    ???

    If not, is the wisdom behind the backslash just to produce result that
    is one of the 3 Types returned by the backslash? This one-liner, BTW,
    is one of my all time favorites. The simplicity of it is staggering.
    Thanks again, three years later, for your excellent contribution.
  • Allen Browne

    #2
    Re: CountInstance() was a beautiful contribution by Doug Steele a few years back...

    Yes, Doug has a good way of thinking of things.

    You probably recognise / as the division operator.
    The \ is the integer division operator.

    You can see the difference if you open the Immediate Window (Ctrl+G) and
    enter:
    ? (8 - 3) / 3
    ? (8 - 3) \ 3
    The first returns 1.6 recurring. The second performs integer division, so
    just returns 1.

    Len() always returns integers, and the number of characters difference
    should be an exact multiple of the number of characters to find, so there
    should not be any difference between the result of integer division or
    normal floating point division. There could be a slight performance
    difference, i.e. integer division could be faster.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "MLH" <CRCI@NorthStat e.netwrote in message
    news:9389449u87 fvknh7bo19e6802 mushm6651@4ax.c om...
    Douglas j.Steele contributed Wed, Aug 11 2004 6:15 pm.
    Replace$ is not available in A97. Chuck Grimsby took care
    of that with his airing of the JoeReplace FN.
    >
    My Q here today is to Doug, in regard to the use of the backslash...
    >
    Is there ever an instance where
    CountInstances = (Len(ToSearch) - Len(JoeReplace( ToSearch, ToFind,
    vbNullString))) \ Len(ToFind)
    >
    would return a value different than
    CountInstances = (Len(ToSearch) - Len(JoeReplace( ToSearch, ToFind,
    vbNullString))) / Len(ToFind)
    ???
    >
    If not, is the wisdom behind the backslash just to produce result that
    is one of the 3 Types returned by the backslash? This one-liner, BTW,
    is one of my all time favorites. The simplicity of it is staggering.
    Thanks again, three years later, for your excellent contribution.

    Comment

    Working...