473,795 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2984
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.co m

"Daniel Rimmelzwaan" <da************ ****@nospam.tec tura.com> wrote in
message news:u8******** ******@TK2MSFTN GP10.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.c om> wrote in
message news:OQ******** ******@TK2MSFTN GP15.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.co m

"Daniel Rimmelzwaan" <da************ ****@nospam.tec tura.com> wrote in
message news:u8******** ******@TK2MSFTN GP10.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(o bject sender, System.EventArg s e)
{
string orig = "\u0002";
XmlTextWriter w = new XmlTextWriter(" c:\\test.xml",
new System.Text.UTF 8Encoding(false , true));

w.WriteElementS tring("elementX ", orig);
w.Close();

XmlTextReader r = new XmlTextReader(" c:\\test.xml");
string str2 = r.ReadElementSt ring("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.tec tura.com> wrote in
message news:uN******** ******@TK2MSFTN GP14.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
3349
by: Maileen | last post by:
Hi, How can we convert string^ to String or to LPCWSTR ? thx, Maileen
1
12716
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 know, Using Encoding.UTF8.GetString(data) can get a ASCII string, but I need a byte. I hope you get my point. Any suggestion will be appreciated.
4
17377
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
13566
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} System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string s = new string((char)107, 1); s += new string((char)62, 1);
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.