469,603 Members | 2,347 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

Missing £ (pound) sign

When using StreamReader/Writer to process an input text file to an output
text file the pound signs (£) simply disappear. Sample code:

StreamReader sr = new StreamReader("input.txt");
StreamWriter sw = new StreamWriter("output.txt");
string Line;
char [] delimiter = {'*'};
while((Line = sr.ReadLine()) != null)
{
string[] Fields;
Fields = Line.Split(delimiter);
foreach (string thisField in Fields)
{
sw.WriteLine(thisField);
}
sw.WriteLine("******************");
}
sr.Close();
sw.Close();

Any ideas folks? I'm pulling my hair out and have very little to spare!
--
Many thanks for any help
Anthony Ward
Nov 16 '05 #1
6 6485
Hold onnnnnnn..........

StreamReader sr = new StreamReader("input.txt", System.Text.Encoding.UTF7);

Nirosh.

"Anthony" <An*****@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
When using StreamReader/Writer to process an input text file to an output
text file the pound signs () simply disappear. Sample code:

StreamReader sr = new StreamReader("input.txt");
StreamWriter sw = new StreamWriter("output.txt");
string Line;
char [] delimiter = {'*'};
while((Line = sr.ReadLine()) != null)
{
string[] Fields;
Fields = Line.Split(delimiter);
foreach (string thisField in Fields)
{
sw.WriteLine(thisField);
}
sw.WriteLine("******************");
}
sr.Close();
sw.Close();

Any ideas folks? I'm pulling my hair out and have very little to spare!
--
Many thanks for any help
Anthony Ward

Nov 16 '05 #2
Champika Nirosh <te**@test.lk> wrote:
Hold onnnnnnn..........

StreamReader sr = new StreamReader("input.txt", System.Text.Encoding.UTF7);


Almost certainly not. UTF7 is a pretty rarely used encoding, in my
experience.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Anthony <An*****@discussions.microsoft.com> wrote:
When using StreamReader/Writer to process an input text file to an output
text file the pound signs (?) simply disappear. Sample code:

StreamReader sr = new StreamReader("input.txt");
StreamWriter sw = new StreamWriter("output.txt");
string Line;
char [] delimiter = {'*'};
while((Line = sr.ReadLine()) != null)
{
string[] Fields;
Fields = Line.Split(delimiter);
foreach (string thisField in Fields)
{
sw.WriteLine(thisField);
}
sw.WriteLine("******************");
}
sr.Close();
sw.Close();

Any ideas folks? I'm pulling my hair out and have very little to spare!


What encoding is the file in? It's probably in the default encoding for
the system, in which case, specifying Encoding.Default in the
constructor for the StreamReader (and StreamWriter) should fix the
problem.

Note that using statements would make your code more robust - currently
you're not closing the reader/writer if an exception is thrown.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
mmm I guess you are correct..

but what is happening with ur mail client .. what encoding does it use...

I mean to convert pound to "=A3"
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Champika Nirosh <te**@test.lk> wrote:
Hold onnnnnnn..........

StreamReader sr = new StreamReader("input.txt",
System.Text.Encoding.UTF7);
Almost certainly not. UTF7 is a pretty rarely used encoding, in my
experience.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Champika Nirosh <te**@test.lk> wrote:
mmm I guess you are correct..

but what is happening with ur mail client .. what encoding does it use...

I mean to convert pound to "=A3"


Yes, mail clients use UTF-7 sometimes, but I think they're virtually
the only things that *do* use UTF-7.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Following your observations I convert the input text file toUnicode (simply
saving in notepad) and it all worked a dream - silly me of course, now I see
the light - so once again, many thanks, Anthony

"Anthony" wrote:
When using StreamReader/Writer to process an input text file to an output
text file the pound signs (£) simply disappear. Sample code:

StreamReader sr = new StreamReader("input.txt");
StreamWriter sw = new StreamWriter("output.txt");
string Line;
char [] delimiter = {'*'};
while((Line = sr.ReadLine()) != null)
{
string[] Fields;
Fields = Line.Split(delimiter);
foreach (string thisField in Fields)
{
sw.WriteLine(thisField);
}
sw.WriteLine("******************");
}
sr.Close();
sw.Close();

Any ideas folks? I'm pulling my hair out and have very little to spare!
--
Many thanks for any help
Anthony Ward

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Robert Zierhofer | last post: by
4 posts views Thread by ben | last post: by
5 posts views Thread by Waldy | last post: by
3 posts views Thread by quat | last post: by
4 posts views Thread by monomaniac21 | last post: by
8 posts views Thread by davoti | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.