How to handle every character within a 'StreamReader'?

F

francescomoi

Hi.

I want to make a script which reads a file and shows its contents:
------------
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream(),
System.Text.Encoding.GetEncoding("iso-8859-15")))
{
result = sr.ReadToEnd();
sr.Close();
}
return result;
-----------

It works fine, but it doesn't show euro symbol ('x80') correctly.

I want to handle every character and, when it's 'x80' I can convert it
to 'EUR' word.

How can I handle every character within a 'StreamReader'?

Thank you very much,
--F
 
J

Jon Skeet [C# MVP]

I want to make a script which reads a file and shows its contents:
------------
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream(),
System.Text.Encoding.GetEncoding("iso-8859-15")))
{
result = sr.ReadToEnd();
sr.Close();
}
return result;

Have you worked out whether that's due to how you're reading it or how
you're displaying it?
I want to handle every character and, when it's 'x80' I can convert it
to 'EUR' word.

How can I handle every character within a 'StreamReader'?

Well, you could read a character at a time - but it may be
significantly more efficient to read a chunk at a time (using
Read(buffer, index, size)) and only act on buffers which have
problematic parts in them.

Alternatively, unless the files are particularly big, you could read it
as you already are doing, and then just use String.Replace to replace
the Euro cahracter with "EUR". Not as efficient, but really simple.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top