Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo can any one help me please,

i want to delete data present in Comments

Forexample:

//#define 0
//#define 1
/*#define 2*/
/*#define 3
#define 4*/
#define 5
/* abcd

*/

// efgh



// #define 6
#define 7
/* #define 8
#define 9
// #define 10

output should be:
#define 5
#define 7
#define 9

i tried thisway,

string line; string str;
StringBuilder sb = new StringBuilder();

// Read the file and display it line by line.
using (System.IO.StreamReader file = new System.IO.StreamReader("FilePath"))
{
while ((line = file.ReadLine()) != null)
{
if (line.Contains("#define"))
{

str = line;

sb.AppendLine(line.ToString());


}
}
}
str = sb.ToString();


string pattern = @"(//[\t|\s|\w|\d|\.]*[\r\n|\n])|([\s|\t]*/\*[\t|\s|\w|\W|\d|\.|\r|\n]*\*/)|(\<[!%][ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t%]*)\>)";


Regex rx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection mc = rx.Matches(str);

foreach (Match m in mc)
{

str = str.Replace(m.Value, "");
MessageBox.Show(str);
}

but am not able to read all till file end, it reads upto #define 10 , there is a one line empty ,its stopping there, i want to read all data between #define and delete comment's data, thanks
Posted

1 solution

 
Share this answer
 
Comments
getanswer 12-Jun-13 5:09am    
thanks , right answer, in output it show deleted row with empty space............

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