TeekUS <Te****@teekus. com> wrote:
Jon ---> no i dont think i am losing data. The BSCs sometimes just send
down some rubbish in their files for a reason we do not yet know. right
now all i need is to take these characters out so that my parser can run
smoothly. (if i replace the character with any other english character,
it is handeld correctly)Sugge stions??
Well, the easiest way would be to do something like:
1) Read the file line by line
2) For each line, check whether or not there are any non-ASCII
characters
3) If there are, use ToCharArray to get a character array for the
string, then run through that array and convert any non-ASCII character
into '?', then convert the char array to a string
4) Do whatever you want to do with the line.
Something like:
using (StreamReader reader = ...)
{
string line;
while ( (line=reader.Re adLine())!=null )
{
bool hasNonAscii=fal se;
foreach (char c in line)
{
if (c > 127)
{
hasNonAscii=tru e;
break;
}
}
if (hasNonAscii)
{
char[] chars = line.ToCharArra y();
for (int i=0; i < chars.Length; i++)
{
if (chars[i] > 127)
{
chars[i]='?';
}
}
line = new string(chars);
}
// Do whatever with line
}
}
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too