Wednesday, May 16, 2012

deleting text only after comment(--)

My project is currently spposd to delete all thetext after the -- signs, as it represents a comment.
my code now is deleting all the text in the text in the text file, een before the comment.



here is my code so far:



static void Main( string[] args )
{
string line = null;
string line_to_delete = "--";
string desktopLocation = Environment.GetFolderPath( Environment.SpecialFolder.Desktop );
string text = Path.Combine( desktopLocation, "tim3.txt" );
string file = Path.Combine( desktopLocation, "tim4.txt" );

using (StreamReader reader = new StreamReader( text ))
{
using (StreamWriter writer = new StreamWriter( file ))
{
while (( line = reader.ReadLine() ) != null)
{
if (string.Compare( line, line_to_delete ) == 0)
File.WriteAllText( file, File.ReadAllText( text ).Replace( line_to_delete, "" ) );
continue;
}
}


how can i specify that it must only delete the te
Thanks





No comments:

Post a Comment