纠正在数据库中的文本? [英] Correcting text in database?
问题描述
问:
在我的数据库之一,有一个VARCHAR字段的值: 经纪人México,Intermediario德Aseguro,SA
In one of my database, there is a value in a varchar-field: Brokers México, Intermediario de Aseguro,S.A.
现在我提出一个新的列作为nvarchar和想要接管旧的价值观,正确连接codeD。
Now I make a new column as nvarchar, and want to take over the old values, properly encoded.
现在两个问题:
A)
在C#/ VB.NET,我怎样才能改变México回到正确的值(墨),将其存储在UNI code场前(假设我知道正确的源 - codePAGE)?
Now two questions:
A)
In C#/VB.NET, how can I change México back to the proper value ("México"), before storing it in the unicode field (assuming I know the proper source-codepage)?
B)
有没有办法找出codePAGE,如果我不想做手工? (当然,问的是免费的,但我想是没有的)。
B)
Is there a way to figure out the codepage, if I don't want to do it manually ? (well, asking is free, but I suppose there is none).
推荐答案
您可能需要的尝试的是这样的:
You might want to try something like this:
string broken = "Brokers México, Intermediario de Aseguro,S.A."; // Get text from database
byte[] encoded = Encoding.GetEncoding(28591).GetBytes(broken);
string corrected = Encoding.UTF8.GetString(encoded);
这实际上取决于它如何被插入 - 这是假设的东西已经采取UTF-8字节,除preTED他们为ISO-8859-1字符串,然后插入该字符串到数据库中。基本上,code执行完全相反的转换。
It really depends on how it's been inserted - that's assuming that something has taken UTF-8 bytes, interpreted them as an ISO-8859-1 string, and then inserted that string into the database. Basically the code performs the same conversion in reverse.
我不知道搞清楚code网页 - 我的猜到的为ISO-8859-1和UTF-8开始,如果不工作,看看什么是错的,正确版本的一些例子。
I'm not sure about figuring out the code page - I would guess at ISO-8859-1 and UTF-8 to start with, and if that doesn't work, look at some examples of what's wrong and the correct version.
这篇关于纠正在数据库中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!