The below are the set of log data found in text file
**********************************************************************************
**2008/04/06** 00:35:35 193111 1008 O 9448050132# 74
**2008/04/06** 00:35:35 193116 1009 O 9448050132# 74
**12/15/2008** 8:36AM 106 01 090788573 00:01'23" ..06
**10/10/2008** 14:32:32 4400 4653 00:00:56 26656 0 0 OG AL#
& 0000 0000
N 124 00 8630 T001045 **10/16** 05:04 00:01:02 A 34439242360098
***************************************************************************************
I need to extract only date details(may be 200/04/06 or 10/16) from all of the above lines and display it in textbox.
I know how to segregate date if the data is ordered like below
***************************************************************************************
10/10/2008 14:32:32 4400 4653 00:00:56 26656 0 0 OG AL#
10/10/2008 14:33:29 4400 4653 00:00:02 26656434 0 0 OG LL#
10/10/2008 14:33:31 4400 4653 00:00:11 26656434 0 0 OG LL#
***************************************************************************************
The code for it is:
StreamReader rr = File.OpenText("C:/1.txt");
string input = null;
while ((input = rr.ReadLine()) != null)
{
char[] seps = { ' ' };
string[] sd = input.Split(seps, StringSplitOptions.RemoveEmptyEntries);
string[] l = new string[1000];
for (int i = 0; i < sd.Length; i++)
{
l[i] = sd[i];
textBox4.AppendText(l[i] + "\r\n");
//The date is 10 characters in length. ex:06/08/2008
if (l[i].Length == 10)
textBox1.AppendText(l[i]+"\r\n");
//The time is of 8 characters in length. ex:00:04:09
if (l[i].Length == 8)
textBox2.AppendText(l[i] + "\r\n");
//The phone is of 11 characters in length. ex:9480455302#
if (l[i].Length == 11)
textBox3.AppendText(l[i] + "\r\n");
}
}
Can you please help me with this!!!!
There are a few oddities in your code. Most notably, the following line inside the while loop:
This will create a 1000-element string array for each round in the while loop. Later, you will use only element
iin that array, leaving the 999 other elements unused. Judging from the rest of the code, you could just as well simply usesd[i].Also, I am guessing that textBox1, textBox2 and textBox3 should never contain the same value; if a value goes into one of them, it should never go into another one of them (except textBox4 that seem to collect all data). Then there is also no need to keep testing the value, once the correct textbox is found.
Finally the following line inside the while loop:
This will create an identical character array for each round in the while loop; you can move that outside the loop and just reuse the same array.
As for the date detection; from the data that you present, the date is the only data that contains a / character, so you could test for that rather than the length.
You can try the following: