sample code looks like this...
class FileReader
{
//from here i need read that file
}
file looks like this:
#AutoSar_Start
Message $591 NM_AUTOSAR NM_AUTOSAR IPC 8 1000
Signal NM_AUTOSAR_signal NM_AUTOSAR_signal 8 0 7 HEX $0 $0 $0 $0
Message $58C ACU_Autosar ACM_AutoSar_Network_Mgmt IAM 8 0
Signal AutoSar ACM_AutoSar_Network_Mgmt 64 0 63 HEX $0 $0 $FFFF $0
#AutoSar_End
when i encounter #AutoSar_Start till #AutoSar_End i should skip while reading..
Loading
Subhendu DePosted Dec 8, 2010, 8:57 AM
My file contains following things...
//Start
blah.. blah.. blah
#AutoSar_Start
Message $591 NM_AUTOSAR NM_AUTOSAR IPC 8 1000
Signal NM_AUTOSAR_signal NM_AUTOSAR_signal 8 0 7 HEX $0 $0 $0 $0
Message $58C ACU_Autosar ACM_AutoSar_Network_Mgmt IAM 8 0
Signal AutoSar ACM_AutoSar_Network_Mgmt 64 0 63 HEX $0 $0 $FFFF $0
#AutoSar_End
blah.. blah.. blah
// End
The code should be
string line;
bool flag = false;
StreamReader sr = new StreamReader(@"C:\Users\sude\Documents\username.txt");
while ((line = sr.ReadLine())!=null)
{
if ((!flag)&&(line.Equals("#AutoSar_Start")))
{
flag = true;
}
else if (line.Equals("#AutoSar_End"))
{
flag = false;
}
else if (flag)
{
//do nothing
}
else
{
Console.WriteLine(line);
}
I test it but I want you to test the code and feel free to post to me how could I make the code more cleaner.....
Please revert back if you have any issues.....