7
Reply

The first character of my String is printing "?"

Michael Jacquet

Michael Jacquet

10 years ago
834
Hello,
I am new to programming and I have a strange issue.
I read lines from a textfile and throw theim separetly in an String Array.
Everything is working fine except that when I  WriteLine(Array[0]) it writes in the console:
?My sentence bla bla bla....
 
All others element of the array write just fine... 
Another odd thing is that when I use the imediate window to ask about that element, it writes it just fine.
 
Here is the code... If someone can figure out my mistake, it would be awesome.
Thank you!
 
(I didn't find a way to show the code properly so I hope it s readable)
namespace Radio
{
class Program
{
static void Main(string[] args)
{
StreamReader myReader = new StreamReader(@"playlist.txt");
String line = "";
int compteur = 0;
Console.WriteLine("Ordre normal :");
while(line != null)
{
line = myReader.ReadLine();
if(line!=null)
{
Console.WriteLine(line);
compteur++;
}
}
Console.WriteLine("Nombre de chansons dans la playlist:" + compteur.ToString());
String[] ordreNorm = new string[compteur];
myReader.BaseStream.Position = 0;
for (int i = 0; i < compteur; i++)
{
ordreNorm[i] = myReader.ReadLine();
}
foreach (string song in ordreNorm)
{
Console.WriteLine(song);
}
Console.WriteLine(ordreNorm[0]);
Console.ReadLine();
}
}
}

Answers (7)