473,320 Members | 1,828 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,320 software developers and data experts.

Convert OEM to Unicode

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

Similar topics

6
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
5
by: [Yosi] | last post by:
Hi, I have a string array includes unicode data, how can I print the char (real string), for example: "\x08\x03\x34\0.\0\x39\0" What should I do, I want to see the char of this array of unicode....
2
by: Joebloggs | last post by:
Hi I am trying to do an ldap lookup. I can pick up the domain name in the standard format DOMAIN\USERNAME. The problem is the company I work for expects the query in the format DOMAIN:USERNAME....
10
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
8
by: csanjith | last post by:
Hi, i have a situaion where i need to convert the characters entered in an text field to upper case using C. The configuration id utf8 environment in which user can enter any character (single ,...
1
by: recover | last post by:
#include <xxx> int main() { const wchar* pwcHello=L"hello"; char* pcHello; xxxxxx //do something using stl cout<<pcHello<<endl; } =============out===========
3
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what...
0
by: deloford | last post by:
Hi This is going to be a question for anyone who is an expert in C# Text Encoding. My situation is this: I have a Sybase database which is firing back ISO-8559 encoded strings. I am unable to...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.