By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,564 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,564 IT Pros & Developers. It's quick & easy.

alt Key combination

P: n/a
Can anyone please give me the code for "alt+156" incode Thanks
Nov 16 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
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?
On Mon, 7 Mar 2005 14:24:47 +0200, Harry <ob*****@absamail.co.za> wrote:
Can anyone please give me the code for "alt+156" incode Thanks


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

P: n/a
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"
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsm9o2ojgklbvpo@pbn_computer...
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?
On Mon, 7 Mar 2005 14:24:47 +0200, Harry <ob*****@absamail.co.za> wrote:
Can anyone please give me the code for "alt+156" incode Thanks


--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3

P: n/a
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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4

P: n/a
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

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsm9qv2paklbvpo@pbn_computer...
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.

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #5

P: n/a
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))
{
}

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #6

P: n/a
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?)

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsnbf22k4klbvpo@pbn_computer...
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))
{
}

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #7

P: n/a
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).

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #8

P: n/a
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();

}

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsnbnwppaklbvpo@pbn_computer...
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).

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #9

P: n/a
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

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsnbnwppaklbvpo@pbn_computer...
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).

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #10

P: n/a
The error in my code is caused when I assume that the byte[] b contains
characters encoded in UTF7, so when I use GetString and decode the bytes I
get an error in the resulting string.

There are two ways to fix this. Either create a byte array using UTF7 or
decode the byte array using UTF8

byte[] b = Encoding.UTF7.GetBytes(s);
string t = Encoding.UTF7.GetString(b);

byte[] b = Encoding.UTF8.GetBytes(s);
string t = Encoding.UTF8.GetString(b);

I'm guessing you don't have the ability to change the decoder (UTF7), so
hence the change in the
encoder (when creating the StreamWriter).
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #11

P: n/a
On Wed, 9 Mar 2005 15:44:57 +0200, Harry <ob*****@absamail.co.za> wrote:
I put this line in
using System.Text.Encoding.UTF7;// (and ...UTF7).


Put only

using System.Text;

'using' statements can only be used for namespaces. 'Encoding' is a class
inside the 'System.Text' namespace. Putting 'using System.Text' saves
time because when you later write Encoding... the compiler will check all
the 'using' statements and find the Encoding class in the System.Text
namespace. Since 'Encoding' is a class and 'UTF7' is a property of the
Encoding class you can't put those in a 'using' statement.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #12

P: n/a
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();
}
}
------------------------------------------
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsne279aaklbvpo@pbn_computer...
On Wed, 9 Mar 2005 15:44:57 +0200, Harry <ob*****@absamail.co.za> wrote:
I put this line in
using System.Text.Encoding.UTF7;// (and ...UTF7).


Put only

using System.Text;

'using' statements can only be used for namespaces. 'Encoding' is a class
inside the 'System.Text' namespace. Putting 'using System.Text' saves
time because when you later write Encoding... the compiler will check all
the 'using' statements and find the Encoding class in the System.Text
namespace. Since 'Encoding' is a class and 'UTF7' is a property of the
Encoding class you can't put those in a 'using' statement.

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #13

P: n/a
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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #14

P: n/a
OK thanks again for you effort It was great
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsngyd6hsklbvpo@pbn_computer...
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.

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.