473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Count Nos in string

101 100+
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 1381
missinglinq
3,532 Expert 2GB
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
billa856
101 100+
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
billa856
101 100+
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
8,834 Expert 8TB
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
3,532 Expert 2GB
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

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

Similar topics

0
by: Ireneus Broncel | last post by:
I have a class which reads Groups and Users from ActiveDirectory. The Problem is, that i have about 10000 rows as product. When I am trying to read the "memberOf" Objects out of this field i get...
10
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
3
by: Kuups | last post by:
Hi! I have a question regarding the count if character within a string like for example I have a string of e.g. 123#123# I would like to determine what is the code? of getting the # sign
3
by: chrisperkins99 | last post by:
It seems to me that str.count is awfully slow. Is there some reason for this? Evidence: ######## str.count time test ######## import string import time import array s = string.printable *...
24
by: Derek Hart | last post by:
Is there an efficient line of code to count the number of instances of one string within another. If I have the sentence: "I want to go to the park, and then go home." It would give me a...
7
by: Matteo Rattotti | last post by:
Hi all, i've noticed a strange beaviour of string.count: in my mind this code must work in this way: str = "a_a_a_a_" howmuch = str.count("_a_") print howmuch -> 3
2
by: GoCoogs | last post by:
I'm trying to count how many items are in a dynamic collection. This is the code I have so far. *** Begin Code *** Public Class Rule Private _rulevars As RuleVarsCollection Private _rulename...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
3
by: waynejr25 | last post by:
can anyone debug my program and get it to run. #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <map> using namespace std;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.