VB编码Ascii - >统一 [英] VB Encoding Ascii -> Unicode

查看:141
本文介绍了VB编码Ascii - >统一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

我需要您的帮助以解决以下问题。



在现有数据库中,ASCII代码中有条目例如希腊语。因为旧的Programm是在vb6中编程的,程序员修改了数据库中的文本条目。



例如,希腊语数据库中的文本是:Ðïëýôïîéêããéáôïõò ääñüâéïõòïñãáíéóìïýò。



现在我想将文本转换为Unicode并将其写入另一个数据库。



我试图将文本设置为TextBox.Text并将font属性设置为'Arial Greek'然后一切看起来都不错,但如果我想将数据写入数据库,TextBox.text只给出了不可读的字符串。



请原谅我不太好的英语。



谢谢!


$ b $bBjörn

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

推荐答案

更准确地说,Unicode,UTF-16是Windows和.NET中使用的本机字符串表示形式不必担心这一部分。 技巧是使用正确的扩展ASCII代码页正确解码输入字符串。在MSDN上有一个例子,偶然使用希腊语:



如何:在传统编码和Unicode之间进行转换(C#编程指南) [ ^ ]



附录:您正在寻找的代码页可能是1253.无论如何,这里是完整列表:编码类(.NET Framework 4.5) [< a href =http://msdn.microsoft.com/en-us/library/vstudio/system.text.encoding.aspxtarget =_ blanktitle =New Window> ^ ]



附录2:您可能还想进行架构更改。如果字符串是扩展的ASCII,我猜测列类型是char和/或varchar。考虑将这些更改为nchar / nvarchar以避免来回转换。
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.


谢谢谢尔盖和丹尼斯!



与您的想法和解决方案我编写了一个函数,它给了我想要的结果。



H代码:





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:


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)







所以我可以把这个字符串写入数据库和我的世界很好!!



谢谢


$ b $bBjörn




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

Thanks

Björn

这篇关于VB编码Ascii - &gt;统一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆