Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi there.
I need your help für the following Problem.

In an existing Database there are entries in ASCII Code for e.g. greek. Becouse the old Programm is programmed in vb6 the programmer has modified the text entries in the Database.

For e.g the Text in the Database for greek is: Ðïëý ôïîéêü ãéá ôïõò õäñüâéïõò ïñãáíéóìïýò.

Now i want to transform the text into Unicode and write it into another Database.

I have tried to set the text to a TextBox.Text and set the font property to 'Arial Greek' then everything look good, but if i want to write the Data to the database the TextBox.text gives me only the not readable string.

Please excuse my not so good english.

Thanks!

Björn
Posted
Comments
Sergey Alexandrovich Kryukov 13-Aug-13 15:36pm    
Actually, "Ðïëý ôïîéêü ãéá ôïõò õäñüâéïõò ïñãáíéóìïýò" is not Unicode and not ASCII. This is some Windows encoding, quite obsolete.
You can work with Unicode with VB6, for example, via raw Windows API, but most part of it does not support Unicode. Do you have any particular reason to work with such thing as VB6, which was obsolete well before it was presented to market? (No wonder it gain popularity in certain type of any key people. :-) I would not waste a minute for this problem. What's the use?

Do yourself a great favor: forget about this trash a nightmare. Of forget about Unicode and... a lot more.

—SA
Member 8810464 13-Aug-13 15:46pm    
Thank you for your answer! The Problem is, that there is a Programm programmed with VB6 and now i want to rewrite it into .Net. i have thought that at first the Database has to change into a Unicode Database. So i search a way to convert the 'Windows encoding' into Unicode

Unicode, UTF-16 more precisely, is the native string representation used in both Windows and .NET so you don't have to worry about that part. The "trick" is to correctly decode the input string using the correct extended ASCII code page. There's an example on MSDN which incidentally even uses Greek:

How to: Convert Between Legacy Encodings and Unicode (C# Programming Guide)[^]

Addendum: The code page you're looking for is probably 1253. In any event, here's a full list: Encoding Class (.NET Framework 4.5)[^]

Addendum 2: You'll probably also want to make a schema change. If the strings are in extended ASCII I would guess the column types are char and/or varchar. Consider changing these to nchar/nvarchar to avoid converting back and forth.
 
Share this answer
 
v3
Comments
Member 8810464 13-Aug-13 15:49pm    
Thank you i will have a look at this MS Page tomorrow morning.
Sergey Alexandrovich Kryukov 13-Aug-13 15:52pm    
It's all fine or .NET, but VB6... what shall OP do with Unicode in this case?..

And by the way, this is just the bad Microsoft jargon, when the term "Unicode" is used as "UTF-16LE". In fact, despite the fact that UTF-16LE is used internally, in memory, modern versions of Windows really support fully-fledged Unicode, pretty much abstracted from particular UTF.

—SA
Dennis C. Dietrich 13-Aug-13 16:05pm    
The OP has extended ASCII strings in a database which in itself has nothing to do with VB6 (getting into that state probably did). I can't know what the OP should do but the two options are keeping the database as is and converting to Unicode on reads and to ASCII on writes. Or make a schema change, convert everything in one go and then just keep using Unicode. I would tend to the latter but without more details I can't say which approach makes more sense.

As for "Unicode", you are mistaken. Unicode starting with version 2.0 simply defines code points which is really nothing more than a list of characters and their numerical value in Unicode. You still have to encode these somehow for storage in memory, files, etc. (the code space is 21-bit). UTF-16 is one of those encodings (see http://www.unicode.org/faq/utf_bom.html).
Sergey Alexandrovich Kryukov 13-Aug-13 16:32pm    
Yes, that's right, I know, I mean practically, what's the use of doing right things with Unicode with VB6, if everything else is, well... VB6? For example, UI is not Unicode-aware, and so on...
—SA
Thank you Sergey and Dannis!

with your idears and solutions i have coded a function which gives me the result i want.

Hiere the code:


VB
Dim enc As System.Text.Encoding = Encoding.Default


'Windows Greek Codepage 1253

' Specify the code page to correctly interpret byte values
Dim encoding__1 As Encoding = Encoding.GetEncoding(codepage)

'put the string into Bytes
Dim codePageValues As Byte() = enc.GetBytes("Ðïëý ôïîéêü ãéá ôïõò õäñüâéïõò ïñãáíéóìïýò")


' Same content is now encoded as UTF-16
Dim unicodeValues As String = encoding__1.GetString(codePageValues)

System.Windows.Forms.MessageBox.Show(unicodeValues)



So i could write this string into a Database and my World is fine!!

Thanks

Björn
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900