By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,488 Members | 2,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,488 IT Pros & Developers. It's quick & easy.

Count Nos in string

100+
P: 101
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.
Jul 22 '08 #1
Share this Question
Share on Google+
5 Replies


missinglinq
Expert 2.5K+
P: 3,532
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

Expand|Select|Wrap|Line Numbers
  1. NosCount = (Len([YourString]) - Len(Replace([YourString], ","; ""))) + 1
  2.  
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

Expand|Select|Wrap|Line Numbers
  1. NosCount =  Len([YourString]) - Len(Replace([YourString], ","; ""))
  2.  
Linq ;0)>
Jul 22 '08 #2

100+
P: 101
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

Expand|Select|Wrap|Line Numbers
  1. NosCount = (Len([YourString]) - Len(Replace([YourString], ","; ""))) + 1
  2.  
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

Expand|Select|Wrap|Line Numbers
  1. NosCount =  Len([YourString]) - Len(Replace([YourString], ","; ""))
  2.  
Linq ;0)>
There is an error missing list operator.can u plz check its format?
Jul 23 '08 #3

100+
P: 101
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.
Jul 28 '08 #4

ADezii
Expert 5K+
P: 8,597
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function test(strToTest As String) As Integer
  2. Dim ara As Variant
  3. Dim I As Integer
  4. Dim Count As Integer
  5.  
  6. ara = Split(strToTest, ";")
  7.  
  8. Count = 0
  9.  
  10. For I = LBound(ara) To UBound(ara)
  11.   If IsNumeric(ara(I)) And ara(I) > 0 Then
  12.     Count = Count + 1
  13.   Else
  14.   End If
  15. Next I
  16.  
  17. test = Count
  18. End Function
Jul 28 '08 #5

missinglinq
Expert 2.5K+
P: 3,532
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)>
Jul 28 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.