hi,
i have a file like this :
test 1: 1110 1 4 faults detected
G17 /0
G11 /1
G9 /0
G8 /1
test 2: 1111 1 0 faults detected
test 3: 0011 1 3 faults detected
G5 /0
G10 /0
G14 /1
test 4: 0111 1 5 faults detected
G15 /1
G6 /1
G11->G6 /1
G12 /1
G1 /0
test 5: 1110 1 0 faults detected
test 6: 1101 1 0 faults detected
test 7: 1011 1 0 faults detected
test 8: 0100 1 0 faults detected
test 9: 0110 1 0 faults detected
test 10: 0011 0 10 faults detected
G17 /1
G12->G15 /0
G3 /0
G11 /0
G10 /1
G14->G10 /0
G14 /0
G12 /0
G2 /0
G13 /1
test 11: 1111 1 1 faults detected
G14->G8 /1
test 12: 1101 1 0 faults detected
test 13: 1011 1 0 faults detected
test 14: 1111 1 0 faults detected
test 15: 0110 1 0 faults detected
and i want to sum every number before "faults detected". for example: 4+3+5+10+1.
hwo can i do this?
Loading
aurelian cdPosted Apr 16, 2009, 1:41 AM
Manish Dwivedi your possibility was a good one.
Blocked AccountPosted Apr 15, 2009, 6:22 AM
Hi,
try this code
System.IO.
StreamReader file = new System.IO.StreamReader("C:/FaultFile.txt"); string line; int Sum =0; while ((line = file.ReadLine()) != null){
if (line.Contains("faults")){
line = line.Substring(line.LastIndexOf(
" faults") - 3, 3); if (int.Parse(line.Trim()) > 0)Sum +=
int.Parse(line.Trim());}
}
LabelValue.Text=
"Fault :"+ Sum.ToString();Niradhip ChakrabortyPosted Apr 15, 2009, 4:56 AM
Check out:
1.http://www.c-sharpcorner.com/UploadFile/psingh/ReadafileusingCSharp12032005000755AM/ReadafileusingCSharp.aspx
2.http://fullycoded.com/?p=221
3.http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx
Vimal KandasamyPosted Apr 15, 2009, 1:29 AM
it may not exact...but i hope it will help you...
{String[] arr = x.Split(' ');