435,041 Members | 1,793 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,041 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
5 Replies

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

 Expert 5K+ P: 8,638 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 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 Jul 28 '08 #5

 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 