Click here to Skip to main content
11,431,829 members (64,152 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 11-Jun-13 23:26pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
getanswer at 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)



Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 12 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100