Hi I have the following issue.
I have a character that is return by a SQL Server database "É" to be
precise, the issue is that when I store character in a .net string
variable my understanding is that it converts it to UTF-16
automatically. I've seen a lot of quotes saying "All String datatype
variables in .NET are UTF-16 encoded". The thing is that I want to
write this character to a XML file in UTF-8 encoded format instead. How
do I go about doing this?
Right now I've tried the following scenerio's (all in VB.Net) when
writing to my XmlTextWriter object:
1) Encoding the string into UTF-8 bytes, then placing the string into
a Stream Reader and then from there reading the stream into the
XmlTextWriter
Dim utf8 As New UTF8Encoding(Tr ue)
Dim fNameBytes As Byte() = utf8.GetBytes(s trFName)
Dim stmFName As StreamReader = _
New StreamReader( New MemoryStream( fNameBytes ), utf8)
....
EFSXml_UserInfo .WriteAttribute String("firstna me",
stmFName.ReadTo End() )
2) I've also tried the code below:
Dim utf8 As New UTF8Encoding(Tr ue)
Dim xtrFName As XmlTextReader = _
New XmlTextReader(N ew StringReader(st rFName))
Dim msFName As MemoryStream = New MemoryStream()
Dim xtwFName As XmlTextWriter = New XmlTextWriter(m sFName, utf8)
xtwFName.WriteN ode(xtrFName, false)
xtwFName.Flush( )
msFName.Positio n = 0
Dim srFName As StreamReader = New StreamReader(ms FName)
....
EFSXml_UserInfo .WriteAttribute String("firstna me", srFName
..ReadToEnd() )
Neither of the 2 result in encoding the string correctly, can someone
please help me out, I've spend close to 2 days trying to figure this
stupid thing out.
Thanks,
Mike Murray