Count Nos in string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • billa856
    New Member
    • Nov 2007
    • 101

    Count Nos in string

    Hi,
    I have string like below and i wanna count nos in that string

    1st string ;0;80;0;0;39;0; 0;0;81;42;5;100 ;0;0 in this string there are 6 Nos.

    2nd string ;11;0;5;2;0;0;0 ;0;89;65;0;26;0 ;2;5 in this line there are 8 Nos.

    3rd string ;0;0;0;0;50;41; 20;30;0;50;0 in this line there are 5 Nos.

    I can count total nos in string

    1st string -14 Nos.
    2nd string -15 Nos.
    3rd String - 11 Nos.

    can anyone help please?
    Thank You.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Assuming you're running Acc2000 or later version:

    If your “Nos” are not preceded by a semi-colon, i.e.

    0;80;0;0;39;0;0 ;0;81;42;5;100; 0;0

    Code:
    NosCount = (Len([YourString]) - Len(Replace([YourString], ","; ""))) + 1
    If your “Nos” are preceded by a semi-colon, i.e

    ;0;80;0;0;39;0; 0;0;81;42;5;100 ;0;0

    Code:
    NosCount =  Len([YourString]) - Len(Replace([YourString], ","; ""))
    Linq ;0)>

    Comment

    • billa856
      New Member
      • Nov 2007
      • 101

      #3
      Originally posted by missinglinq
      Assuming you're running Acc2000 or later version:

      If your “Nos” are not preceded by a semi-colon, i.e.

      0;80;0;0;39;0;0 ;0;81;42;5;100; 0;0

      Code:
      NosCount = (Len([YourString]) - Len(Replace([YourString], ","; ""))) + 1
      If your “Nos” are preceded by a semi-colon, i.e

      ;0;80;0;0;39;0; 0;0;81;42;5;100 ;0;0

      Code:
      NosCount =  Len([YourString]) - Len(Replace([YourString], ","; ""))
      Linq ;0)>
      There is an error missing list operator.can u plz check its format?

      Comment

      • billa856
        New Member
        • Nov 2007
        • 101

        #4
        I used this fuction and its working fine.

        Public Function test(strToTest As String) As Integer
        Dim strTest As String
        Dim ara() As String
        Dim I As Integer
        Dim Count As Integer
        strTest = strToTest
        ara = Split(strTest, ";")
        Count = 0
        For I = 0 To UBound(ara)
        If ara(I) = "0 " Or ara(I) = ";0 " Or ara(I) = "" Then
        Else
        Count = Count + 1
        End If
        Next I

        test = Count
        End Function

        By the way thanks for ur reply.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by billa856
          I used this fuction and its working fine.
          Here is another option for you:
          Public Function test(strToTest As String) As Integer
          Dim strTest As String
          Dim ara() As String
          Dim I As Integer
          Dim Count As Integer
          strTest = strToTest
          ara = Split(strTest, ";")
          Count = 0
          For I = 0 To UBound(ara)
          If ara(I) = "0 " Or ara(I) = ";0 " Or ara(I) = "" Then
          Else
          Count = Count + 1
          End If
          Next I

          test = Count
          By the way thanks for ur reply.
          Here is another option for you:
          Code:
          Public Function test(strToTest As String) As Integer
          Dim ara As Variant
          Dim I As Integer
          Dim Count As Integer
          
          ara = Split(strToTest, ";")
          
          Count = 0
          
          For I = LBound(ara) To UBound(ara)
            If IsNumeric(ara(I)) And ara(I) > 0 Then
              Count = Count + 1
            Else
            End If
          Next I
          
          test = Count
          End Function

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Sorry I am late getting back to you. The code I posted worked fine in testing, and is, in fact, something I've used for this kind of thing a number of times. My guess is that you either have a typo when you use the code or all of your data was formatted the same as your example.

            At any rate, I'm glad you found something that works!

            Linq ;0)>

            Comment

            Working...