Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

C# how to search textfile and append

public void stack()
    {
        string old;
        string iniPath = Application.StartupPath + "list.ini";
        bool isDeleteSectionFound = false;
        List<string> deleteCodeList = new List<string>();
        using (StreamReader sr = File.OpenText(iniPath))
        {
            while ((old = sr.ReadLine()) != null)
            {
                if (old.Trim().Equals("[DELETE]"))
                {
                    isDeleteSectionFound = true;
                }
                if (isDeleteSectionFound && !old.Trim().Equals("[DELETE]"))
                {
                    deleteCodeList.Add(old.Trim());
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        using (var reader = new StreamReader(File.OpenRead(textBox1.Text)))
        {
            //;

            List<string> data = new List<string>();
            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();
                var values = line.Split('	');

                if (values.Contains(deleteCodeList))// getting that error
                    continue;

                //
                data.Add(string.Join("	", values));

            }
        }
        File.WriteAllText(textBox1.Text, sb.ToString());
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #search #textfile #append
ADD COMMENT
Topic
Name
9+2 =