如何在SQL Server中解码HTML编码的文本? (或ms访问权限!) [英] How to decode html encoded text in sql server? (or ms access!)
本文介绍了如何在SQL Server中解码HTML编码的文本? (或ms访问权限!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一列带有以下格式的文本...
I have a column with text in the following format...
sweet shop
有没有一种方法可以将其直接转换为sql server中的相应文本? (它实际上是一个链接的ms访问数据库,因此我也可以使用访问权限!)
is there a way to convert this directly to it's corresponding text in sql server? (it is actually a linked ms access database so I could also use access too!)
(我认为这种格式也称为数字字符引用,其中包含unicode字符的代码点)
推荐答案
Alex K正确率为99.99%,但是如果您使用命名代码(例如
或£
Alex K is 99.99% correct, however the conversion would fail if you had Named Codes like
or £
因此,这里我们执行强力替换,然后通过XML解析字符串
So, here we perform a brute force replace, and then parse the string via XML
示例
Declare @S nvarchar(max) = 'sweet shop £'
Select @S = replace(@S,MapFrom,MapTo)
From ( values
('"','"'),('&','&'),(''',''''),('<','<'),('>','>'),(' ',' '),('¡','¡'),
('¢','¢'),('£','£'),('¤','¤'),('¥','¥'),('¦','¦'),('§','§'),('¨','¨'),
('©','©'),('ª','ª'),('«','«'),('¬','¬'),('®','®'),('¯','¯'),('°','°'),
('±','±'),('²','²'),('³','³'),('´','´'),('µ','µ'),('¶','¶'),('·','·'),
('¸','¸'),('¹','¹'),('º','º'),('»','»'),('¼','¼'),('½','½'),('¾','¾'),
('¿','¿'),('À','À'),('Á','Á'),('Â','Â'),('Ã','Ã'),('Ä','Ä'),('Å','Å'),
('Æ','Æ'),('Ç','Ç'),('È','È'),('É','É'),('Ê','Ê'),('Ë','Ë'),('Ì','Ì'),
('Í','Í'),('Î','Î'),('Ï','Ï'),('Ð','Ð'),('Ñ','Ñ'),('Ò','Ò'),('Ó','Ó'),
('Ô','Ô'),('Õ','Õ'),('Ö','Ö'),('×','×'),('Ø','Ø'),('Ù','Ù'),('Ú','Ú'),
('Û','Û'),('Ü','Ü'),('Ý','Ý'),('Þ','Þ'),('ß','ß'),('à','à'),('á','á'),
('&;','â'),('ã','ã'),('ä','ä'),('å','å'),('æ','æ'),('ç','ç'),('è','è'),
('é','é'),('ê','ê'),('ë','ë'),('ì','ì'),('í','í'),('î','î'),('ï','ï'),
('ð','ð'),('ñ','ñ'),('ò','ò'),('ó','ó'),('ô','ô'),('õ','õ'),('ö','ö'),
('÷','÷'),('ø','ø'),('ù','ù'),('ú','ú'),('û','û'),('ü','ü'),('ý','ý'),
('þ','þ'),('ÿ','ÿ'),('&','&'),('°','°'),('∞','∞'),('‰','‰'),('⋅','⋅'),
('±','±'),('†','†'),('—','—'),('¬','¬'),('µ','µ'),('€','€'),('£','£'),
('¥','¥'),('¢','¢'),('€','€'),('£','£'),('¥','¥'),('¢','¢')
) A (MapFrom,MapTo)
Select cast(cast(@S as xml) as nvarchar(max))
返回
sweet shop £ -- added a space ( ) and a Pound (£) symbol to the original string
这篇关于如何在SQL Server中解码HTML编码的文本? (或ms访问权限!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文