Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi.

I have to develop a simple parser, to read "block" of text
for example:

C#
/TEST
 {. text .}
/TEST_DATA
 {. infs .}


and, I need to read informations of inside of label....
and... the file with have this informations... have a lot of labels, with the same perfil

for example:

C#
/TEST
 {. text .}
/TEST_DATA
 {. infs .}

/LBL1
 {. text .}
/LBL1_DATA
 {. infs .}

/LBL2
 {. text .}
/LBL2_DATA
 {. infs .}

/LBL3
 {. text .}
/LBL3_DATA
 {. infs .}



i need to read the block of specif label, for example:

parseFile("FileName.txt", LBL1)

and the function, return for me, the text of inside the blocks: LBL1 and LBL1_DATA
or, return for me, the content of LBL1 and LBL1_DATA

Thanks.
Posted
Comments
ZurdoDev 18-Jun-12 14:21pm    
You'll have to write the code to parse it and check each line for what you are looking for. What have you done so far?
nv3 18-Jun-12 14:22pm    
So, what have you tried and where did you get stuck?
Sergey Alexandrovich Kryukov 18-Jun-12 15:24pm    
Not clear what's the problem. How about using "Improve question" above?
--SA

Looks fairly simple to start with, just check each line for a starting / then strip the following code that is delimited by { and }. Maybe you should clarify exactly what part of this you are having difficulty with.
 
Share this answer
 
you can start like this

C#
typedef struct
{
  char* text;
  void* data;
}DATA_INFO;

DATA_INFO& parseFile("FileName.txt", char* label )
{
  char* currentline;
  Openfile;
  getline( currentline );
  remove / from currentline; 
  comparestring( label, currentline );
  {
    DATA_INFO structinfo;
    structinfo.text = read text;
    skip line;
    structinfo.data = read data;
    return structinfo;
  } 
};


And clarify where you have doubt.
 
Share this answer
 
v3
Comments
Richard MacCutchan 19-Jun-12 3:56am    
Please use <pre> tags around source code.
Richard MacCutchan 19-Jun-12 8:36am    
Still wrong - did you look at what the result was?
Binu MD 19-Jun-12 20:38pm    
updated, thanks for your comment.

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