All pastes #152679 Raw Edit

Something

public text v1 · immutable
#152679 ·published 2006-08-29 01:29 UTC
rendered paste body
//This algorithm leaves nothing but the text indented. Why?


TextReader r = new StreamReader(File.Open(fname, FileMode.Open));
            string contents = r.ReadToEnd();
            r.Close();
            string[] x = contents.Split(new string[] { "\r\n" },
                StringSplitOptions.RemoveEmptyEntries);

            List<string> select = new List<string>();
            string temp = Console.ReadLine();
            while (!temp.Equals(""))
            {
                select.Add(temp);
                temp = Console.ReadLine();
            }

            int start;
            for (start = 0; start < x.Length && !x[start].Equals(select[0]);
                start++) ;

            TextWriter o = new StreamWriter(File.Open(fname, FileMode.Truncate));
            bool alreadyDone = false;
            for (int i = 0; i < x.Length; i++)
            {
                if (i < start || alreadyDone)
                    o.WriteLine(x[i]);
                else
                {
                    for (int j = 0; j < select.Count; i++,j++)
                        o.WriteLine(tabs + select[j]);
                    alreadyDone = true;
                }
            }
            o.Close();