Search
 
SCRIPT & CODE EXAMPLE
 

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());
    }
Comment

C# how to search textfile and append

using System.IO;
using System.Linq;

static void Main(string[] args)
{
     var reader = new StreamReader(File.OpenRead(@"C:	est.ini"));

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

            if (values.Contains("REMOVE"))
                continue;

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

        }

        //Inside data you have all the lines without the removed. You can rewrite
        //to other file 


}
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# USING SHARED CLASS 
Csharp :: where are the viwes in .net core publish 
Csharp :: unknown discriminator value mongodb 
Csharp :: c# array of class objects initialization with constructor 
Csharp :: blazor data annotation diaply name 
Csharp :: how to make a console feedback 
Csharp :: backcolor app winform C3 
Csharp :: linked list follow what in c# 
Csharp :: store file in DB 
Csharp :: list.SkipWhile in c# 
Csharp :: c# user and password verification 
Csharp :: call a .NET assembly from C or c++ 
Csharp :: difference between %e/E, %f/F and %g/G in program C 
Csharp :: unity check if swipe not tap 
Csharp :: Rotate Object/Camera by Mouse 
Csharp :: C# Bitwise Left Shift 
Csharp :: c# 9.0 dynamic nedir 
Csharp :: stackoverflow array c# 
Csharp :: Using a Views in .net and c# 
Csharp :: two question marks together mean in C# 
Csharp :: ASP.NET Web Forms TextBox 
Csharp :: asp net identity login failed for user 
Csharp :: sterge element din coada c# 
Csharp :: IOS app crashing on ios 15 unity 
Csharp :: trigger enter with nav mesh 
Csharp :: translate english to spanish 
Csharp :: enable asnotracking in asp.net core at global level 
Csharp :: How to put a (new line) inside a list box 
Csharp :: entity save example in c# model first 
Csharp :: in model add to give drop down message 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =