Remove control and non-ASCII characters from large files I get huge incoming files (up to 6GB) and they are littered with Control and non-ASCII characters.  I need to strip them and I made this routine (below).  The problem is that it is insanely slow.  I would love any thoughts or advice on how I can speed it up.  

public void StripHighBitCharacters(string fn)
{
    string writeFile = fn + "B";
    using (var reader = new StreamReader(fn))
    using (var writer = new StreamWriter(writeFile))
    {
        while (!reader.EndOfStream)
        {
            string line = reader.ReadLine();
            if (line.Length &gt; 0)
            {
                writer.WriteLine(BuildClearString(line));
            }
            else
            {
                writer.WriteLine(line);
            }
        }
    }
    File.Copy(writeFile, fn, true);
    File.Delete(writeFile);
}
public string BuildClearString(string line)
{

    StringBuilder sb = new StringBuilder();

    foreach (char c in line)
    {
        if (c &gt;= 32 &amp;&amp; c &lt;= 175)
        {
            sb.Append(c);
        }
    }

    return (sb.ToString());
}
One source of performance degradation is frequent memory allocations.  In your case, the StringBuilder will allocate space for every line in your file, and may allocate additional space (along with a data copy) for longer lines.

You can eliminate all of that by reusing the StringBuilder object.  At the start of BuildClearString, call the clear method on it (sb.Clear(); or sb.Length = 0;).  Follow that up by a capacity check.

if (sb.Capacity &lt; line.Length)
    sb.Capacity = line.Length;


By changing the capacity you ensure that you have a buffer big enough to hold all the characters you will be adding, so you won't incur any memory allocations when processing a line.  By reusing it, you keep the existing allocated memory, thus avoiding any allocations for later lines unless the line is longer than any you've already encountered.  You can also set an initial capacity on the StringBuilder object.