Extract content in note pad

Hi All…
Good Day:)

I have to convert the csv file into notepad. it has 200 lines, after that I have extract each 20 line from that note pad and each 20 lines save it to the new notepad. That each note pad has to be save in different name
I am having trouble on extracting 20 lines part.

can anyone pls help me with this ?
Thanks In Advance:)

Hi @soundarya_A1 ,
You can try this step
1.read csv to get data table,
2.for each data table with in32 variable count
with 20 to write a text file
I will try a sample for you then send you later
You can try
CSV to TXT.zip (19.1 KB)

regards,

Hi @soundarya_A1

Try below way:

1. Read CSV File
   - Output: DataTable

2. Assign activity
   - Index = 0
   - Counter = 1

3. While activity
   - Condition: Index < DataTable.Rows.Count
   - Body:
     a. Write Text File
        - File: "Notepad_" + Counter.ToString() + ".txt"
        - Text: String.Join(Environment.NewLine, Enumerable.Range(Index, Math.Min(20, DataTable.Rows.Count - Index)).Select(Function(r) String.Join(",", DataTable.Rows(r).ItemArray)))
     b. Assign activity
        - Index = Index + 20
        - Counter = Counter + 1

4. End While

Hope it helps!!

1 Like

is a skip / take pattern
nowadays we can handle (projectcompatibilty: windows) with chunk(Segmentsize)

Illustrating the chunk approach

Reading the file, already split into lines:
grafik

Chunk it (kindly note the defensive handling of incomplete segments - Line16-18)
grafik

Details:
grafik

So, we can:

  • iterate over the segements with a for each activity
  • write out the segment with a Write TextFile Activity

Hi @soundarya_A1 ,

The solution will publish in YouTube by tomorrow (22-Dec-2023 at 5PM)

Video Link:- https://youtu.be/UqOqwyuQVjk

Regards,
Pavan kumar

1 Like

Hi @soundarya_A1

->Read CSV File (Output=dt_Data)
->Output DataTable (Output=CSV_Data_
->Write Text File (Input=CSV_Data)

Then

  1. Read that Text File - Var: TextFile

  2. Use Assign Activity
    Lines(type: Array of String)=TextFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)

  3. Use While Loop – Create a Var Name StartIndex(Type: Int32)
    Conditaion StartIndex<Lines.Length

    Use Assign Activity
    Create a string variable called currentLine
    currentLine= String.Join(Environment.NewLine, Lines.Skip(startIndex).Take(20))

    Use Write Text Activity
    "“output_” + (startIndex \ 20).ToString(“D2”) + “.txt”
    startIndex = startIndex + 20

1 Like

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