I try to get first character occurrence in text keeping their original order. I try to use LINQ but I’m very new in this, so something is wrong, and I have bad result.
For example I write: “languages”, so the result would l-0, a-1, n-2, g-3, u-4, e-7, s-8 (digit mean index of occurrence). But my code gives: l-0, a-1, n-2, g-3, u-4, e-5, s-6.
So index number is 0,1,2,3,4,5 no matter what. That’s my code:
char[] result = text.ToLower()
.Where(char.IsLetter)
.GroupBy(x => x)
.Select(g => g.Key).ToArray();
for (int i = 0; i < result.Length; i++)
{
listView1.Items.Add(result[i].ToString());
listView1.Items[i].SubItems.Add(i.ToString());
}
I would use
Regex:And a non-regex alternative: