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

Convert DOS Cyrillic text to Unicode

P: n/a
How can I convert DOS cyrillic text to Unicode
Nov 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
* "Nikolay Petrov" <jo******@mail.bg> scripsit:
How can I convert DOS cyrillic text to Unicode


Take a look at the 'System.Text.Encoding' class.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #2

P: n/a
I am doing this all day ;-)
still nothing ;-)

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
* "Nikolay Petrov" <jo******@mail.bg> scripsit:
How can I convert DOS cyrillic text to Unicode


Take a look at the 'System.Text.Encoding' class.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 20 '05 #3

P: n/a
LOL
I am doing this all day ;-)
still nothing ;-)
How can I convert DOS cyrillic text to Unicode


Take a look at the 'System.Text.Encoding' class.

Nov 20 '05 #4

P: n/a
did i mention that this is going to be my first app ;-)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...
LOL
I am doing this all day ;-)
still nothing ;-)
> How can I convert DOS cyrillic text to Unicode

Take a look at the 'System.Text.Encoding' class.


Nov 20 '05 #5

P: n/a
Hi Nikolay,

Send some code in advance, when you have luck Jay will help you, you can
send this as well to the newsgroup.

Microsoft.public.dotnet.general

There you have a change that Jon Skeet will help you.

They are the two who do the most encoding problems.

Cor
Nov 20 '05 #6

P: n/a
Nikolay,
In addition to the other comments

What is the Code Page for DOS Cyrillic? Quickly checking MSDN I think its
866, but you need to double check!

You would use Encoding.GetEncoding to get the DOS Cyrillic Encoding object.

Imports System.Text

Dim cyrillic As Encoding = Encoding.GetEncoding(866)

Given an array of Bytes with DOS Cyrillic in it, you would use
Encoding.GetString to convert to a Unicode String.

Dim bytes() As Byte
Dim s As String = cyrillic.GetString(bytes)

Given a Unicode String, you would us Encoding.GetBytes to get an array of
Bytes with DOS cyrillic.

bytes = cyrillic.GetBytes(s)

If your DOS cyrillic is in a Text File you pass the Encoding object to your
System.IO reader & writer classes

Dim input As New StreamReader("myCyrillic.txt", cyrillic)

Dim output As New StreamWriter("myCyrillic.txt", False, cyrillic)

For information on Unicode, Encoding, and code pages (such as DOS Cyrillic)
see:

http://www.yoda.arachsys.com/csharp/unicode.html

One last thing: Once you have a String it is Unicode! Only Byte arrays &
Streams contain DOS Cyrillic and other character encodings.

Hope this helps
Jay

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
How can I convert DOS cyrillic text to Unicode

Nov 20 '05 #7

P: n/a
Thanks Cor

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
Hi Nikolay,

Send some code in advance, when you have luck Jay will help you, you can
send this as well to the newsgroup.

Microsoft.public.dotnet.general

There you have a change that Jon Skeet will help you.

They are the two who do the most encoding problems.

Cor

Nov 20 '05 #8

P: n/a
That was very helpfull.
But I have some problems. Let me first tell you exactly what I want to
achieve.
I've made a simple ASP .NET page with two text boxes and a button.
What I need is, that a user paste DOS cyrillic text (taken from Notepad) in
left text box,
and when he clicks the button, the Converted to Unicode text to appear at
the right box.
So I get the DOS text as String, not as bytes. How should I proceed in this
case?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
Nikolay,
In addition to the other comments

What is the Code Page for DOS Cyrillic? Quickly checking MSDN I think its
866, but you need to double check!

You would use Encoding.GetEncoding to get the DOS Cyrillic Encoding object.
Imports System.Text

Dim cyrillic As Encoding = Encoding.GetEncoding(866)

Given an array of Bytes with DOS Cyrillic in it, you would use
Encoding.GetString to convert to a Unicode String.

Dim bytes() As Byte
Dim s As String = cyrillic.GetString(bytes)

Given a Unicode String, you would us Encoding.GetBytes to get an array of
Bytes with DOS cyrillic.

bytes = cyrillic.GetBytes(s)

If your DOS cyrillic is in a Text File you pass the Encoding object to your System.IO reader & writer classes

Dim input As New StreamReader("myCyrillic.txt", cyrillic)

Dim output As New StreamWriter("myCyrillic.txt", False, cyrillic)

For information on Unicode, Encoding, and code pages (such as DOS Cyrillic) see:

http://www.yoda.arachsys.com/csharp/unicode.html

One last thing: Once you have a String it is Unicode! Only Byte arrays &
Streams contain DOS Cyrillic and other character encodings.

Hope this helps
Jay

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
How can I convert DOS cyrillic text to Unicode


Nov 20 '05 #9

P: n/a
Nikolay,
What I need is, that a user paste DOS Cyrillic text (taken from Notepad) in left text box, I would expect Notepad will have Windows Cyrillic or Unicode or think it
has, depending on the version of Windows & your regional settings in Control
Panel.
So I get the DOS text as String, not as bytes. How should I proceed in this case? No you don't get DOS text as a String!

Strings in .NET are always Unicode! Period.

Notepad, the browser & ASP.NET has already converted your "DOS text" into
Unicode for you. As I stated Notepad made an assumption of what kind of text
it is, then the browser used some encoding, such as UTF-8 or Windows
Cyrillic to send the response to ASP.NET as a stream of bytes. ASP.NET then
converted this response stream of bytes into a Unicode String. Hence your
program now has a Unicode string!

I've only used the normal encoding for requests & response in ASP.NET, so
I'm not certain on how to use a specific encoding for requests & responses.

Unfortunately you will need to ask in one of the ASP.NET newsgroups, such as
microsoft.public.dotnet.framework.aspnet for specifics on specific encodings
on requests & responses...

Notice that in the above there is a whole lot of converting going on! Once
your user opened the file in Notepad it was converted, an assumption was
made about the type of text in the file (I strongly suspect the assumption
was not DOS Cyrillic). Then when you cut & pasted the text from notepad to
your browser a conversion may have been made, but more then likely it was
done in the code page of your regional settings in windows, then when you
submitted the page to ASP.NET a conversion is made from the request/response
encoding into Unicode. So by the time ASP.NET gets you text is has already
been converted for you, so it is no where near DOC Cyrillic any more.

If you have files with DOS Cyrillic in them and you need or want to use
ASP.NET to convert them to Unicode I would recommend rather then using a
notepad, a text box and cut & paste. That you use the input type=file HTML
control to upload your DOS Cyrillic to the server as a stream of bytes
(preserving the DOS Cyrillic), then using the encoding object as I showed to
read this stream validly converting it to Unicode.

Hope this helps
Jay

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl... That was very helpfull.
But I have some problems. Let me first tell you exactly what I want to
achieve.
I've made a simple ASP .NET page with two text boxes and a button.
What I need is, that a user paste DOS cyrillic text (taken from Notepad) in left text box,
and when he clicks the button, the Converted to Unicode text to appear at
the right box.
So I get the DOS text as String, not as bytes. How should I proceed in this case?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
Nikolay,
In addition to the other comments

What is the Code Page for DOS Cyrillic? Quickly checking MSDN I think its 866, but you need to double check!

You would use Encoding.GetEncoding to get the DOS Cyrillic Encoding

object.

Imports System.Text

Dim cyrillic As Encoding = Encoding.GetEncoding(866)

Given an array of Bytes with DOS Cyrillic in it, you would use
Encoding.GetString to convert to a Unicode String.

Dim bytes() As Byte
Dim s As String = cyrillic.GetString(bytes)

Given a Unicode String, you would us Encoding.GetBytes to get an array of Bytes with DOS cyrillic.

bytes = cyrillic.GetBytes(s)

If your DOS cyrillic is in a Text File you pass the Encoding object to

your
System.IO reader & writer classes

Dim input As New StreamReader("myCyrillic.txt", cyrillic)

Dim output As New StreamWriter("myCyrillic.txt", False, cyrillic)

For information on Unicode, Encoding, and code pages (such as DOS

Cyrillic)
see:

http://www.yoda.arachsys.com/csharp/unicode.html

One last thing: Once you have a String it is Unicode! Only Byte arrays &
Streams contain DOS Cyrillic and other character encodings.

Hope this helps
Jay

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
How can I convert DOS cyrillic text to Unicode



Nov 20 '05 #10

P: n/a
Definitely, Jay. Thank you!
I've got it working allready.
Thank you again.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Nikolay,
What I need is, that a user paste DOS Cyrillic text (taken from Notepad) in
left text box,

I would expect Notepad will have Windows Cyrillic or Unicode or think it
has, depending on the version of Windows & your regional settings in

Control Panel.
So I get the DOS text as String, not as bytes. How should I proceed in this
case?

No you don't get DOS text as a String!

Strings in .NET are always Unicode! Period.

Notepad, the browser & ASP.NET has already converted your "DOS text" into
Unicode for you. As I stated Notepad made an assumption of what kind of

text it is, then the browser used some encoding, such as UTF-8 or Windows
Cyrillic to send the response to ASP.NET as a stream of bytes. ASP.NET then converted this response stream of bytes into a Unicode String. Hence your
program now has a Unicode string!

I've only used the normal encoding for requests & response in ASP.NET, so
I'm not certain on how to use a specific encoding for requests & responses.
Unfortunately you will need to ask in one of the ASP.NET newsgroups, such as microsoft.public.dotnet.framework.aspnet for specifics on specific encodings on requests & responses...

Notice that in the above there is a whole lot of converting going on! Once
your user opened the file in Notepad it was converted, an assumption was
made about the type of text in the file (I strongly suspect the assumption
was not DOS Cyrillic). Then when you cut & pasted the text from notepad to
your browser a conversion may have been made, but more then likely it was
done in the code page of your regional settings in windows, then when you
submitted the page to ASP.NET a conversion is made from the request/response encoding into Unicode. So by the time ASP.NET gets you text is has already
been converted for you, so it is no where near DOC Cyrillic any more.

If you have files with DOS Cyrillic in them and you need or want to use
ASP.NET to convert them to Unicode I would recommend rather then using a
notepad, a text box and cut & paste. That you use the input type=file HTML
control to upload your DOS Cyrillic to the server as a stream of bytes
(preserving the DOS Cyrillic), then using the encoding object as I showed to read this stream validly converting it to Unicode.

Hope this helps
Jay

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
That was very helpfull.
But I have some problems. Let me first tell you exactly what I want to
achieve.
I've made a simple ASP .NET page with two text boxes and a button.
What I need is, that a user paste DOS cyrillic text (taken from Notepad)

in
left text box,
and when he clicks the button, the Converted to Unicode text to appear at
the right box.
So I get the DOS text as String, not as bytes. How should I proceed in

this
case?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:ut**************@TK2MSFTNGP12.phx.gbl...
Nikolay,
In addition to the other comments

What is the Code Page for DOS Cyrillic? Quickly checking MSDN I think

its 866, but you need to double check!

You would use Encoding.GetEncoding to get the DOS Cyrillic Encoding

object.

Imports System.Text

Dim cyrillic As Encoding = Encoding.GetEncoding(866)

Given an array of Bytes with DOS Cyrillic in it, you would use
Encoding.GetString to convert to a Unicode String.

Dim bytes() As Byte
Dim s As String = cyrillic.GetString(bytes)

Given a Unicode String, you would us Encoding.GetBytes to get an array of Bytes with DOS cyrillic.

bytes = cyrillic.GetBytes(s)

If your DOS cyrillic is in a Text File you pass the Encoding object to

your
System.IO reader & writer classes

Dim input As New StreamReader("myCyrillic.txt", cyrillic)

Dim output As New StreamWriter("myCyrillic.txt", False, cyrillic)

For information on Unicode, Encoding, and code pages (such as DOS

Cyrillic)
see:

http://www.yoda.arachsys.com/csharp/unicode.html

One last thing: Once you have a String it is Unicode! Only Byte arrays & Streams contain DOS Cyrillic and other character encodings.

Hope this helps
Jay

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
> How can I convert DOS cyrillic text to Unicode
>
>



Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.