How can I filter duplicate words in a text file down to a single word and store it in a variable?

I want to filter duplicate data in a text file down to a single data and store it in a variable. how can i do

Best regards

Hi @Famui_Yanisa

Try this

uniqueRows = fileText.Split(Environment.NewLine.ToCharArray()).Distinct().ToArray()

I hope it works!!

1 Like

Hi @Famui_Yanisa ,

You could try Reading the Text file using Read Text File activity, then based on the data shown, we can split the data based on the NewLine character and perform a Distinct operation to store only Unique data.

NewTextData = String.Join(Environment.NewLine,Split(TextData,Environment.NewLine).Distinct.ToArray)

Here, NewTextData and TextData are String variables, where TextData is the Output from Read Text File activity.

1 Like

Hi @Famui_Yanisa

  1. Use the “Read Text File” activity to read the contents of the text file into a string variable.
  2. Use the “Assign” activity to convert the text string into a list of strings. You can use the “Split” function to split the text by newlines (“\n”) and store the result in a list variable.
Assign filteredList = str_Text.Split(Environment.NewLine.ToCharArray())
  1. Use the “Assign” activity with LINQ query to remove duplicates from the list.
Assign filteredList = filteredList.Distinct().ToArray()
  1. use the “Assign” activity again to convert the list back to a text string.
Assign filteredText = String.Join(Environment.NewLine, filteredList)
  1. Use the “Write Text File” activity to write the filtered text back to the text file.

Uploaded workflow file for reference with your given input
Sequence10.xaml (11.4 KB)

Hope it helps!!
Regards,

@Famui_Yanisa

If you got the solution for your query. Please mark it as solution to close the thread and others also helped.

Regards,

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