This is my code:
string textToEncode = File.ReadAllText(@"C:\Users\ASUS\Desktop\szyfrowanie2\TextSample.txt");
textToEncode = textToEncode.ToLower();
char[] distinctLetters = textToEncode.Distinct().ToArray();
var count = textToEncode.Distinct().Count();
Console.WriteLine("Letters used in text: \n\n");
for (int i = 0; i < count; i++)
{
if (Equals(distinctLetters[i]," "))
{
Console.Write("<space>");
}
else
{
Console.Write(" " + distinctLetters[i] + " ");
}
}
I want to read the .txt file, turn it all to lowercases by ToLower();
method, but then when I want to read all the distinct characters from .txt file and then write them on screen, they don't show up. Yet later when I use
for (int i = 0; i < distinctLetters.Length; i++)
{
Console.Write("Swap " + distinctLetters[i] + " with ");
it shows the letter that indeed was changed into a lowercase, but wasn't visible on screen by first for
loop. First word in my TextSample.txt
file is "With". The first loop only shows
i t h
But as the second loop starts, it asks
Swap w with
and I have no idea why.
Also the if
statement in first loop doesn't work, it doesn't detect the space.