• XSS.stack #1 – первый литературный журнал от юзеров форума

Clean CSV for Leads

DimmuBurgor

CPU register
Пользователь
Регистрация
01.12.2021
Сообщения
1 504
Решения
1
Реакции
552
Гарант сделки
6
C#:
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
Open the input CSV file for reading
        StreamReader reader = new StreamReader("input.csv");

Open the output CSV file for writing
        StreamWriter writer = new StreamWriter("output.csv");

Write the header to the output CSV file
writer. WriteLine("First Name,Last Name,Email");

Read the input CSV file line by line
while (!reader. EndOfStream)
        {
string line = reader. ReadLine();

Split the line into an array of values
string[] values = line. Split(',');

Extract the first and last name and email from the array
            string firstName = values[0];
            string lastName = values[1];
            string email = values[15];

Write the first name, last name, and email to the output CSV file
writer. WriteLine("{0},{1},{2}", firstName, lastName, email);
        }

Close the reader and writer
reader. Close();
writer. Close();

        Console.WriteLine("Output saved to output.csv.");
    }
}

Next I'll modify it to include winforms to select input from file explorer. Nothing spectacular but I'm just starting out so I'm happy =)
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх