Get unique value in the string/array that's generated from forloop


#1

Hi,

So I have a forloop that loop through an array and put all the items into a string using string.join.
But I only need distinct value in the array. How to do that? Thanks

Lavina


#2

Hi @lavint,
Try this .

arrVariable= arrVariable.Distinct().ToArray()

Below i have attached the sample file : ExcelToArray.zip (7.9 KB)

Regards
Balamurugan


#3

Hi @balupad14,

Sorry actually my variable is a IEnumberable instead of array so I still have some issues on type of the variable when trying your solution. But then I found out a way to use if statement in the forloop of my IEnumberable - so it works that way… But will it be possible to use something similar to your solution and apply it to IEnumberable? I am still kind of confused about IEnumberable actually and thought it’s kind of array…

If not, don’t worry. The sample that you gave is very helpful for future use on Array!! Thank you :smiley:

Warm regards,
Lavina


#4

HI @lavint,
I think Yes. If possible , can you share the source to give a clear solution.

Regards
Balamurugan


#5

@lavint would it be possible (maybe even easier) to change you variable type that holds the strings (with duplicates) to an array or does your existing process require the IEnumberable in order to perform to your specs?