Clear Buffer before my Second Console.Read()

  • Thread starter Thread starter - Steve -
  • Start date Start date
S

- Steve -

Okay I call Console.Read() twice. However when I come up on my second
Console.Read() ASCII character 10 is already on the console (that's a line
feed).

How do I clear out that line feed before I call Console.Read() again?
 
Steve,

Can you show the code where this is happening? Console.Read shouldn't
be feeding you the line character (I think).

If anything, why not use ReadLine?
 
char letter = (char)Console.Read();

The first time through it is fine. The second time I can see in the
debbuger the a line feed is already in there.

I'm using Read instead of ReadLine becuase I just want a single char instead
of a string, and it seems like it would be simplier to do it this way.

Of course depending on what it takes to get around this issue I might change
my ind.

Nicholas Paldino said:
Steve,

Can you show the code where this is happening? Console.Read shouldn't
be feeding you the line character (I think).

If anything, why not use ReadLine?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

- Steve - said:
Okay I call Console.Read() twice. However when I come up on my second
Console.Read() ASCII character 10 is already on the console (that's a
line feed).

How do I clear out that line feed before I call Console.Read() again?
 
Steve,

You probably should do a readline. The reason for this is that when
dealing with console input, the buffer is not going to be filled until a
line is entered. Because of this, it's easier to just read the line and
process the string than it is to read character by character.

In .NET 2.0 however, there are ways of detecting when there is a
keypress, which might be of use to you.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

- Steve - said:
char letter = (char)Console.Read();

The first time through it is fine. The second time I can see in the
debbuger the a line feed is already in there.

I'm using Read instead of ReadLine becuase I just want a single char
instead of a string, and it seems like it would be simplier to do it this
way.

Of course depending on what it takes to get around this issue I might
change my ind.

Nicholas Paldino said:
Steve,

Can you show the code where this is happening? Console.Read shouldn't
be feeding you the line character (I think).

If anything, why not use ReadLine?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

- Steve - said:
Okay I call Console.Read() twice. However when I come up on my second
Console.Read() ASCII character 10 is already on the console (that's a
line feed).

How do I clear out that line feed before I call Console.Read() again?
 
Back
Top