473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to count the number of digits in a file?

1 New Member
Can you help me write a program that counts the number of digits in a file?
For example the file contains:

5 6 7 -8 9obvsefs
6 7 8i uhbnm
8 8

And the program returns: "The number of all digits is 10"
Jan 15 '14 #1
3 3773
Luk3r
300 Contributor
Hope this helps!

Expand|Select|Wrap|Line Numbers
  1. //create a string to read your text document
  2. string text = System.IO.File.ReadAllText(@"C:\test.txt");
  3. //replace the spaces with no value so that spaces aren't counted as characters
  4. text = text.Replace(" ", "");
  5. //show the count of actual characters in a document
  6. MessageBox.Show(text.Length.ToString());


Edit*: I just realized I replied with C# in a C question. My apologies.
Jan 15 '14 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
If you know all the digits are in the range 0-9 then you can read your file a byte at a time and call isdigit() on each byte.

Or write your own test:

if ((byte >=0) && (byte <=9)) is true, you have a digit.
Jan 15 '14 #3
Banfa
9,065 Recognized Expert Moderator Expert
I think you'll find that should be

if ((byte >='0') && (byte <='9')) is true, you have a digit.
Jan 16 '14 #4

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

Similar topics

1
by: vic | last post by:
Hello, Dean Try this: select distinct c1, c2 into #tmp_1 from t1 select count(*) as cnt from #tmp_1 drop table #tmp_1 With best regards.
0
by: DataFreakFromUtah | last post by:
Hello! No question here, just a procedure for the archive. Search critera: count records imported count data imported count number of rows imported count number of records imported record import...
4
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I am trying to convert the digits to even number so for example if I have 3 digit number, I want it to be 4 digit and If I have 5 digit number, I want it to be 6 digit. How can i...
5
by: isabelle | last post by:
hi, every body.. I have two program I couldn’t solve them So, can any body help me. please!! 1-Write a program that accepts a character and count number of occurrences in a file. The file...
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
2
by: Brian Simmons | last post by:
Hi All, I'm hoping there's a quick and easy to accomplish this: I've got a CSV file (each row represents a record, and is followed by a NewLine). Is there any way (short of counting the...
8
by: bettina top | last post by:
how can i count the digits of number given by the user
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following code to get the recordset of an external database. Dim dbPatients As Database Dim rsCountPatients As Recordset ' to count number of...
5
by: jambonjamasb | last post by:
I am wanting to create a report that summarises the number of items within a date range. For example I have a FIELD called System_Change. This is a drop down COMBOBOX that uses words like unix,...
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.