473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how can I convert (char)02 into UTF8 string

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
3 2961
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Maileen | last post by:
Hi, How can we convert string^ to String or to LPCWSTR ? thx, Maileen
1
by: Hooyoo | last post by:
I read the content from a file encoded with UTF8 like this: byte data = binaryReader.ReadBytes(file.Length); And next step, I want to transform data to ASCII format, How can I do this? You...
4
by: Man4ish | last post by:
HI , I am trying to convert string into char array of characters.but facing problem. #include <iostream> #include <string> using namespace std; int main() { string t="1,2,3,4,5,6";
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.