views:

197

answers:

1

I am comparing to files by reading it into filestream and comparing byte by byte..now how can i skip whitespaces while comparing?I am using C#.net

+3  A: 
byte b;  

// ....

if (Char.IsWhiteSpace((char) b))
{
   // skip...
}

EDIT: As Eric Lippert points out, this is only correct if the encoding of the file is plain 7-bit ASCII. In any other encoding it will skip relevant bytes. So, you should take into account the encoding of your data.

Mitch Wheat
This is only correct if the encoding of the file is plain 7 bit ASCII. In any other encoding it will skip relevant bytes.
Eric Lippert
@Eric Lippert: Hi, the poster said he was comparing bytes, but you are correct; he should be taking into account the encoding.
Mitch Wheat