Click here to Skip to main content
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)

  Print Answers RSS
0 OriginalGriff 431
1 Afzaal Ahmad Zeeshan 184
2 /\jmot 176
3 Sergey Alexandrovich Kryukov 175
4 Marcin Kozub 175
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 12 Jun 2013
Copyright © CodeProject, 1999-2014
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