alt Key combination

  • Thread starter Thread starter Harry
  • Start date Start date
Hi Harry,

Huh???

No, I can't, because that depends on your codepage which for me would be
the '£' character.
What are you trying to do?
 
I have an application which writes a text file to the phone. When I read
this text file on the phone, and there is a £, I have another character
infront of it which is an A with ^ above it. e.g. A£
My code to write to the file is:
sw.WriteLine (PurchasePrice.ToString("£ #,0"));
I don't get this particular character when viewing the text file on the PC.
This is what I see on the text file: "Purchase Price:£ 10"
 
I suspect this is an encoding problem, although I'm not sure why you then
would be able to see '£' at all.

EUREKA!!!

I have successfully managed to reproduce your error using this piece of
code

string s = "The price is: £ 10";
byte[] b = Encoding.UTF8.GetBytes(s);
string t = Encoding.UTF7.GetString(b);
MessageBox.Show(s + "\r\n" + t);

t is in fact "The price is: £ 10";

Depending on how your send the text to the phone, check the encoding, mail
messages are often UTF7 encoded while the web otherwise is usually UTF8.
 
Many Thanks
Wow that was great BUT!;-)
I do not follow what " UTF7 encoded while the web otherwise is usually
UTF8" means
My Code is
string path = @"\Storage\My Documents\POP\";
string fullPath;
fullPath = Path.GetFullPath(path);
string fullAddress = fullPath + fileName;
using (StreamWriter sw = new StreamWriter (fullAddress))

// sale Price
sw.Write("Sale Price:");
sw.Write (new string(' ', 7));
sw.WriteLine (SalePrice.ToString("£ #,0"));

Would you please correct/add code for me.

Thanks for your effort
 
Most web servers use UTF8 for their pages, while e-mail servers may use
UTF7. I'm not entirely sure of the difference, but I suspect UTF7 does
not handle characters in the range 128-255 very well.

I see you use a StreamWriter without specifying an Encoding, and the
default constructor of the StreamWriter uses the default Encoding of the
System.

Try specifying UTF7 in the constructor of the StreamWriter

using (StreamWriter sw = new StreamWriter (fullAddress, false,
Encoding.UTF7))
{
}
 
Thanks again for your response
using this line at the toop
using (StreamWriter sw = new StreamWriter (fullAddress, false,
Encoding.UTF7))

byte[] b = Encoding.UTF8.GetBytes(PurchasePrice.ToString("£ #,0")); ? is
that correct
now error

The type or namespace name 'Encoding' could not be found (are you missing a
using directive or an assembly reference?)
 
Encoding is found in the System.Text namespace, so if you haven't done so
already add

using System.Text;

to your project. Or you can use the full name System.Text.Encoding.UTF8
(and ...UTF7).
 
Thanks again geeting there slowly
I set it up in the following oder
using (StreamWriter sw = new StreamWriter (fullAddress, false,
Encoding.UTF7))
{
// Purchase Price
sw.Write("Purchase Price:");
sw.Write (new string(' ', 7));
sw.WriteLine (PurchasePrice.ToString("£ #,0")); // Do I alter this line
only ??

How do I alter the above to correct the fault
Your code
string s = "The price is: £ 10";
byte[] b = Encoding.UTF8.GetBytes(s);
string t = Encoding.UTF7.GetString(b);
MessageBox.Show(s + "\r\n" + t);
Which lines do I Use
sw.Close();

}
 
I put this line in
using System.Text.Encoding.UTF7;// (and ...UTF7).

The type or namespace name 'UTF7' does not exist in the class or namespace
'System.Text.Encoding' (are you missing an assembly reference?)
Doesn't like Encoding
 
Thanks again for your effort in trying to help me with my problem.
Unfortunately, I'm not getting it right. I have enclosed the code which I am
using. I would be obliged if you would correct the lines accordingly, as
I'm sure this is getting to be a bore for you! Before this happens, I would
like to have the answer. :-)
Many thanks again.
-------------------------------------------------------
using System.Text; /// at the header

private void menuItem2_Click(object sender, System.EventArgs e)
{
double PurchasePrice = Convert.ToDouble(txtPurchasePrice.Text);

string fileName = txtPropertyAddress.Text +".txt";
string path = @"\Storage\Program Files\SmartUI\";
string fullPath;
fullPath = Path.GetFullPath(path);
string fullAddress = fullPath + fileName;

using (StreamWriter sw = new StreamWriter (fullAddress, false,
Encoding.UTF7))
{
sw.Write ("The Property Investment ");
sw.WriteLine("Calc v8a.0");
sw.WriteLine(DateTime.Now);
sw.WriteLine("--------------------------");

// Address
sw.Write("Property Address:");
sw.Write (new string(' ', 1));
sw.Write (txtPropertyAddress.Text);
sw.WriteLine (".txt");

// Purchase Price
sw.Write("Purchase Price:");
sw.Write (new string(' ', 6));
byte[] b = Encoding.UTF7.GetBytes(PurchasePrice);
string t = Encoding.UTF7.GetString(b);
sw.WriteLine (PurchasePrice.ToString("£ #,0"));

sw.Close();
}
}
------------------------------------------
 
I'm afraid I don't have the answer you seek.

Apart from the lines ...GetBytes/GetString... which aren't needed in your
code, only to demonstrate the problem :), I can't tell from your code what
you do wrong.

I suspect the error happens in the part where you send the .txt file to
the phone. Somewhere along the line the text is read in a different
encoding than it is written in, and it appears be after you create the
file.

You could try different encodings for the StreamWriter and see what
happens and/or if you access to the code that ships the file to the phone,
study that for encoding differences.
 
Back
Top