Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to count number of dates in my textfile?
suppose in full big letter there are 3-4 dates are written so tell me the c# code to get the count of those dates in label control?


thanku
Posted

You can use Regular Expressions to match the dates and then use the matches as you wish.

The following link contains examples how to use RegExp in C#:
Regular Expressions Usage in C#[^]

[EDITED]
BTW, the following regexp might help you:
^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.][0-9]{4}$
 
Share this answer
 
v2
Comments
Olivier Levrey 28-Feb-11 6:19am    
My 5.
Read the file in:
string[] lines = File.ReadAllLines(path);

Process each line:
foreach (string line in lines)
   {
   ...
   }

If the line contains a date, count it:
int count = 0;
...
foreach (string line in lines)
   {
   ...
   count++;
   }

Put the result to a label control:
myLabel.text = "Number of dates = " + count.ToString();

Working out if it contains a date is up to you: I do not know anything about your data format...
 
Share this answer
 
Comments
Olivier Levrey 28-Feb-11 6:19am    
My 5.
Use regular expression to find the matching date. Loop it till no match occurs.

Here is an example

http://www.java2s.com/Code/CSharp/Development-Class/Useregulartoverifyadate.htm[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900