Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StreamReader to find specific text and rewrite file

Status
Not open for further replies.

Netman06

Technical User
Aug 15, 2006
70
US
Hello,

I'm trying to find the best way to read and then find specific text within file and then remove it, using StreamWriter.

I have already created the StreamReader, but now need to find out the best way to find : with the file and remove it, then rewrite file.

Thanks,

Mike
 
I might be able to use stringbuilder, if I know that my file will always have the : on the forth line, can I only replace it with a blank line, and not other lines that contain :, because the another lines have the word cn:, which is correct and not a line that starts with :

static string MinifyB(string p)
{
StringBuilder b = new StringBuilder(p);
b.Replace(" ", string.Empty);
b.Replace(Environment.NewLine, string.Empty);
b.Replace("\\t", string.Empty);
b.Replace(" {", "{");
b.Replace(" :", ":");
b.Replace(": ", ":");
b.Replace(", ", ",");
b.Replace("; ", ";");
b.Replace(";}", "}");
return b.ToString();
}
Thanks,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top