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

how can I convert (char)02 into UTF8 string

P: n/a
Does anyone know how to convert a (char)02 into a UTF8 string that I can put
into an XML element? I've tried all examples that I could find in Visual
Studio help or in google, but I can't get it to work. The one that gives me
the answer will just make my day :).

Thanks,
Daniel.
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Daniel,

I thought that if you specify the encoding on the XmlDocument class, and
then just add the text in string form, it will perform the encoding for you
automatically?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daniel Rimmelzwaan" <da****************@nospam.tectura.com> wrote in
message news:u8**************@TK2MSFTNGP10.phx.gbl...
Does anyone know how to convert a (char)02 into a UTF8 string that I can
put into an XML element? I've tried all examples that I could find in
Visual Studio help or in google, but I can't get it to work. The one that
gives me the answer will just make my day :).

Thanks,
Daniel.

Nov 17 '05 #2

P: n/a
That's what we did, but when we create the element, we get an error saying
something about a special character not being allowed. We've since just
gotten rid of the characters (it was actually (char)02 and (char03) as start
and end delimiters of a status message from an external app), but I'd still
like to know how this works.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OQ**************@TK2MSFTNGP15.phx.gbl...
Daniel,

I thought that if you specify the encoding on the XmlDocument class,
and then just add the text in string form, it will perform the encoding
for you automatically?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daniel Rimmelzwaan" <da****************@nospam.tectura.com> wrote in
message news:u8**************@TK2MSFTNGP10.phx.gbl...
Does anyone know how to convert a (char)02 into a UTF8 string that I can
put into an XML element? I've tried all examples that I could find in
Visual Studio help or in google, but I can't get it to work. The one that
gives me the answer will just make my day :).

Thanks,
Daniel.


Nov 17 '05 #3

P: n/a
Daniel,

Did you try something like :

==
private void button1_Click(object sender, System.EventArgs e)
{
string orig = "\u0002";
XmlTextWriter w = new XmlTextWriter("c:\\test.xml",
new System.Text.UTF8Encoding(false, true));

w.WriteElementString("elementX", orig);
w.Close();

XmlTextReader r = new XmlTextReader("c:\\test.xml");
string str2 = r.ReadElementString("elementX");

if (str2 == orig)
MessageBox.Show("equal");
else
MessageBox.Show("not equal");

r.Close();
}
==

The above code, when run, displays : "equal".
Is this what you are trying to do ?

Stephen
"Daniel Rimmelzwaan" <da****************@nospam.tectura.com> wrote in
message news:uN**************@TK2MSFTNGP14.phx.gbl...
That's what we did, but when we create the element, we get an error saying
something about a special character not being allowed. We've since just
gotten rid of the characters (it was actually (char)02 and (char03) as
start and end delimiters of a status message from an external app), but
I'd still like to know how this works.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.