如何在SQL Server中解码HTML编码的文本? (或ms访问权限!) [英] How to decode html encoded text in sql server? (or ms access!)

查看:107
本文介绍了如何在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
        ('&quot;','"'),('&amp;','&'),('&apos;',''''),('&lt;','<'),('&gt;','>'),('&nbsp;',' '),('&iexcl;','¡'),
        ('&cent;','¢'),('&pound;','£'),('&curren;','¤'),('&yen;','¥'),('&brvbar;','¦'),('&sect;','§'),('&uml;','¨'),
        ('&copy;','©'),('&ordf;','ª'),('&laquo;','«'),('&not;','¬'),('&reg;','®'),('&macr;','¯'),('&deg;','°'),
        ('&plusmn;','±'),('&sup2;','²'),('&sup3;','³'),('&acute;','´'),('&micro;','µ'),('&para;','¶'),('&middot;','·'),
        ('&cedil;','¸'),('&sup1;','¹'),('&ordm;','º'),('&raquo;','»'),('&frac14;','¼'),('&frac12;','½'),('&frac34;','¾'),
        ('&iquest;','¿'),('&Agrave;','À'),('&Aacute;','Á'),('&Acirc;','Â'),('&Atilde;','Ã'),('&Auml;','Ä'),('&Aring;','Å'),
        ('&AElig;','Æ'),('&Ccedil;','Ç'),('&Egrave;','È'),('&Eacute;','É'),('&Ecirc;','Ê'),('&Euml;','Ë'),('&Igrave;','Ì'),
        ('&Iacute;','Í'),('&Icirc;','Î'),('&Iuml;','Ï'),('&ETH;','Ð'),('&Ntilde;','Ñ'),('&Ograve;','Ò'),('&Oacute;','Ó'),
        ('&Ocirc;','Ô'),('&Otilde;','Õ'),('&Ouml;','Ö'),('&times;','×'),('&Oslash;','Ø'),('&Ugrave;','Ù'),('&Uacute;','Ú'),
        ('&Ucirc;','Û'),('&Uuml;','Ü'),('&Yacute;','Ý'),('&THORN;','Þ'),('&szlig;','ß'),('&agrave;','à'),('&aacute;','á'),
        ('&;','â'),('&atilde;','ã'),('&auml;','ä'),('&aring;','å'),('&aelig;','æ'),('&ccedil;','ç'),('&egrave;','è'),
        ('&eacute;','é'),('&ecirc;','ê'),('&euml;','ë'),('&igrave;','ì'),('&iacute;','í'),('&icirc;','î'),('&iuml;','ï'),
        ('&eth;','ð'),('&ntilde;','ñ'),('&ograve;','ò'),('&oacute;','ó'),('&ocirc;','ô'),('&otilde;','õ'),('&ouml;','ö'),
        ('&divide;','÷'),('&oslash;','ø'),('&ugrave;','ù'),('&uacute;','ú'),('&ucirc;','û'),('&uuml;','ü'),('&yacute;','ý'),
        ('&thorn;','þ'),('&yuml;','ÿ'),('&amp;','&'),('&deg;','°'),('&infin;','∞'),('&permil;','‰'),('&sdot;','⋅'),
        ('&plusmn;','±'),('&dagger;','†'),('&mdash;','—'),('&not;','¬'),('&micro;','µ'),('&euro;','€'),('&pound;','£'),
        ('&yen;','¥'),('&cent;','¢'),('&euro;','€'),('&pound;','£'),('&yen;','¥'),('&cent;','¢')
       ) A (MapFrom,MapTo)

Select cast(cast(@S as xml) as nvarchar(max))

返回

sweet shop £  -- added a space (&nbsp;) and a Pound (&pound;) symbol to the original string

这篇关于如何在SQL Server中解码HTML编码的文本? (或ms访问权限!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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