Delete first 2 rows of Note pad

Hi
I want to delete first 2 rows from Note pad in ui path.
can anyone help me with this. Rows are not blank . It contains some junk values.

Thanks in advance.

1 Like

@oshan,

Welcome to UiPath community!.
Read the entire file using read text file activity.
Then split that using newline like strInputFile.Split({Environment.Newline},stringsplitoption.None)

Then remove the first two lines from that string array output from the above line, then write the remaining into the textfile with the same name.

1 Like

@oshan

Welcome to the uipath community.

  1. Use Read Text File Activity to read the data and assign it to one string variable and then split it based on NewLine character like below.

       txtData [] = vartxtData.Split(Environment.NewLine.TocharArray) 
    
      txtData [] = txtData.Skip(2).ToArray()
    
       requiredStr = String.Join(Environment.NewLine,txtData)
    

And then use Write Text File Activity to write into notepad file and pass that string i.e. requiredStr

2 Likes

hi @oshan,

There’s just simple way of doing is using replace with regex
just use assign after your read text file activity,

note (String) = System.Text.RegularExpressions.Regex.Replace(InputText,"^(.*\n){2}","")

here,
InputText —> is output variable of read text file activity
And Regex pattern ("^(.*\n){2}") simply get first 2 rows from the string variable and replaced it with null, now you can use write text file activity and pass that note var in it, that’s it. :slightly_smiling_face:

2 Likes

Hi Samir,

Thanks a lot … this works…

But i had Japanese characters in my note pad. it became junk after Write Text File. Is there any solution to resolve this.

This issue is resolved by encoding it as shift_jis.

Thank you all :slight_smile:

I’m happy to help. :grinning:

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