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

Convert OEM to Unicode

P: n/a
I have a Command Prompt window open and select all the characters and copy
them to the clipboard.

I then read them from the clipboard
str = CType(DataO.GetData(DataFormats.OemText, False), String)

and try to convert them to unicode

Dim InEncoding As Encoding = Encoding.GetEncoding(437)

Dim OutEncoding As Encoding = Encoding.Unicode

Dim StrAsBytes As Byte() = InEncoding.GetBytes(str)

Dim OutEncodingBytes As Byte() = Encoding.Convert(InEncoding, OutEncoding,
StrAsBytes)

Dim OutEncodingChars As Char() = OutEncoding.GetChars(OutEncodingBytes)

textbox1.text= = New String(OutEncodingChars)

But they do not display correctly.

Can you see what is wrong?




Dec 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
" Franky" <fr***********@a-znet.comschrieb:
>I have a Command Prompt window open and select all the characters and copy
them to the clipboard.
[OEM to Unicode]
Take a look at this sample:

<URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Dec 18 '06 #2

P: n/a
I must have seen this example before - some place
because I have tested the statement
Encoding.GetEncoding( _

CultureInfo.InstalledUICulture.TextInfo.OEMCodePag e _

).GetString(Encoding.Default.GetBytes(Text))

and it works .

My problem is that I must be misunderstanding something because the code I
submitted does not work and it seems to me that it should. I'd like to know
what is wrong with it.

Thanks

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:ea**************@TK2MSFTNGP02.phx.gbl...
>" Franky" <fr***********@a-znet.comschrieb:
>>I have a Command Prompt window open and select all the characters and copy
them to the clipboard.
[OEM to Unicode]

Take a look at this sample:

<URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Dec 18 '06 #3

P: n/a
I can make it work but don't understand why.
Change from
Encoding.Convert(InEncoding, OutEncoding
to
Encoding.Convert(OutEncoding,InEncoding
Doc says
Public Shared Function Convert ( _
srcEncoding As Encoding, _
dstEncoding As Encoding, _
bytes As Byte() _
) As Byte()Here is the way I figure it.The string I get from the clipboard,
InStr, is OEM.So InStrAsBytes is an byte array, 1 byte per character.
OEMThat is the source array.and InEncoding is the source encoding.But to
make it work I have to treat it as the destination encoding.Unless the doc
is wrong.Anyone familiar enough with this to correct my analysis?ThanksI
have a Command Prompt window open and select all the characters and copy
them to the clipboard.

I then read them from the clipboard
InStr = CType(DataO.GetData(DataFormats.OemText, False), String)

and try to convert them to unicode

Dim InEncoding As Encoding = Encoding.GetEncoding(437)

Dim OutEncoding As Encoding = Encoding.Unicode

Dim InStrAsBytes As Byte() = InEncoding.GetBytes(InStr)

Dim OutEncodingBytes As Byte() = Encoding.Convert(InEncoding, OutEncoding,
InStrAsBytes)

Dim OutEncodingChars As Char() = OutEncoding.GetChars(OutEncodingBytes)

textbox1.text= = New String(OutEncodingChars)

But they do not display correctly.

Can you see what is wrong?
Dec 19 '06 #4

P: n/a
Scratch the last post. I did NOT work. So I'm back to square one. Why
doesn't the code at the bottom work? What is wrong with it?
....snip bad analysis...
Sorry

I have a Command Prompt window open and select all the characters and copy
them to the clipboard.

I then read them from the clipboard
InStr = CType(DataO.GetData(DataFormats.OemText, False), String)

and try to convert them to unicode

Dim InEncoding As Encoding = Encoding.GetEncoding(437)

Dim OutEncoding As Encoding = Encoding.Unicode

Dim InStrAsBytes As Byte() = InEncoding.GetBytes(InStr)

Dim OutEncodingBytes As Byte() = Encoding.Convert(InEncoding, OutEncoding,
InStrAsBytes)

Dim OutEncodingChars As Char() = OutEncoding.GetChars(OutEncodingBytes)

textbox1.text= = New String(OutEncodingChars)

But they do not display correctly.

Can you see what is wrong?


Dec 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.