I have to delete first 4 rows from CSV

Hi Team,

I have to delete first 4 rows from CSV file

Input:

Output:

Anyone please help

Thanks
Shaik

Hi @Mukthar_Valli

Check the below thread.

Your regex will be changed as below:

strCSV = System.Text.RegularExpressions.Regex.Replace(strCSV,"(?<=^)(.*\n){4}","")

Hope it helps!!

Hi @Mukthar_Valli

Try this,

dt = dt.AsEnumerable().Skip(4).CopyToDataTable()

When CSV File we recommend, not much to work/open/inspect this in Excel but within a mature Texteditor e.g. notepad++

When it is a CSV File, we can do cleansing on the Text File Base directly like:


Text: String.Join(Environment.NewLine, System.IO.File.ReadLines("YourFullPathToTheCSV").Skip(4))

1 Like

Hi @Parvathy

rows are deleted from 2 row not from 1 row, please check

I have to delete first 4 rows

Thanks
Shaik

How about the following expression?

System.Text.RegularExpressions.Regex.Replace(strCSV,"^(.*\n){4}","")

Regards,

Hi @Mukthar_Valli

Try this syntax:

strCSV = System.Text.RegularExpressions.Regex.Replace(strCSV,"(?<=^)(.*\n){4}","")

Hope it helps!!

@Yoichi Thank you it’s working fine

thanks
shaik

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.