Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Classic ASP (VBScript)将HTML代码转换为纯文本

Classic ASP (VBScript)将HTML代码转换为纯文本
EN

Stack Overflow用户
提问于 2011-05-24 19:20:29
回答 2查看 26.4K关注 0票数 14

我正在尝试使用经典的ASP (VBScript)将&#XXXX;(其中XXXX是一个数字)之类的HTML码转换成纯文本。

我将文本添加到纯文本格式的电子邮件中,如果我将它们添加为HTML代码,它只显示代码,而不转换它们。

一种解决方法是将电子邮件改为HTML,它确实解决了这个问题,但会导致我的电子邮件出现其他问题,我将不再深入讨论。

是否有内置函数或自定义函数可用于将这些HTML代码转换为纯文本?

EN

回答 2

Stack Overflow用户

发布于 2017-04-13 13:51:31

一个更夸张的解码器伴随着C. Ross响应

代码语言:javascript
运行
AI代码解释
复制
Function HTMLDecode(sText)
    Dim regEx
    Dim matches
    Dim match
    sText = Replace(sText, """, Chr(34))
    sText = Replace(sText, "<"  , Chr(60))
    sText = Replace(sText, ">"  , Chr(62))
    sText = Replace(sText, "&" , Chr(38))
    sText = Replace(sText, " ", Chr(32))

    sText = Replace(sText, "¡", Chr(161))
    sText = Replace(sText, "£", Chr(163))
    sText = Replace(sText, "¥", Chr(165))
    sText = Replace(sText, "©", Chr(168))
    sText = Replace(sText, "«", Chr(171))
    sText = Replace(sText, "»", Chr(187))
    sText = Replace(sText, "¿", Chr(191))
    sText = Replace(sText, "À", Chr(192))
    sText = Replace(sText, "Á", Chr(193))
    sText = Replace(sText, "Â", Chr(194))
    sText = Replace(sText, "Ã", Chr(195))
    sText = Replace(sText, "Ä", Chr(196))
    sText = Replace(sText, "Å", Chr(197))
    sText = Replace(sText, "Æ", Chr(198))
    sText = Replace(sText, "Ç", Chr(199))
    sText = Replace(sText, "È", Chr(200))
    sText = Replace(sText, "É", Chr(201))
    sText = Replace(sText, "Ê", Chr(202))
    sText = Replace(sText, "Ë", Chr(203))
    sText = Replace(sText, "Ì", Chr(204))
    sText = Replace(sText, "Í", Chr(205))
    sText = Replace(sText, "Î", Chr(206))
    sText = Replace(sText, "Ï", Chr(207))
    sText = Replace(sText, "Ñ", Chr(209))
    sText = Replace(sText, "Ò", Chr(210))
    sText = Replace(sText, "Ó", Chr(211))
    sText = Replace(sText, "Ô", Chr(212))
    sText = Replace(sText, "Õ", Chr(213))
    sText = Replace(sText, "Ö", Chr(214))
    sText = Replace(sText, "×", Chr(215))
    sText = Replace(sText, "Ø", Chr(216))
    sText = Replace(sText, "Ù", Chr(217))
    sText = Replace(sText, "Ú", Chr(218))
    sText = Replace(sText, "Û", Chr(219))
    sText = Replace(sText, "Ü", Chr(220))
    sText = Replace(sText, "Ý", Chr(221))
    sText = Replace(sText, "Þ", Chr(222))
    sText = Replace(sText, "ß", Chr(223))
    sText = Replace(sText, "à", Chr(224))
    sText = Replace(sText, "á", Chr(225))
    sText = Replace(sText, "â", Chr(226))
    sText = Replace(sText, "ã", Chr(227))
    sText = Replace(sText, "ä", Chr(228))
    sText = Replace(sText, "å", Chr(229))
    sText = Replace(sText, "æ", Chr(230))
    sText = Replace(sText, "ç", Chr(231))
    sText = Replace(sText, "è", Chr(232))
    sText = Replace(sText, "é", Chr(233))
    sText = Replace(sText, "ê", Chr(234))
    sText = Replace(sText, "ë", Chr(235))
    sText = Replace(sText, "ì", Chr(236))
    sText = Replace(sText, "í", Chr(237))
    sText = Replace(sText, "î", Chr(238))
    sText = Replace(sText, "ï", Chr(239))
    sText = Replace(sText, "ð", Chr(240))
    sText = Replace(sText, "ñ", Chr(241))
    sText = Replace(sText, "ò", Chr(242))
    sText = Replace(sText, "ó", Chr(243))
    sText = Replace(sText, "ô", Chr(244))
    sText = Replace(sText, "õ", Chr(245))
    sText = Replace(sText, "ö", Chr(246))
    sText = Replace(sText, "÷", Chr(247))
    sText = Replace(sText, "ø", Chr(248))
    sText = Replace(sText, "ù", Chr(249))
    sText = Replace(sText, "ú", Chr(250))
    sText = Replace(sText, "û", Chr(251))
    sText = Replace(sText, "ü", Chr(252))
    sText = Replace(sText, "ý", Chr(253))
    sText = Replace(sText, "þ", Chr(254))
    sText = Replace(sText, "ÿ", Chr(255))

    Set regEx= New RegExp

    With regEx
     .Pattern = "&#(\d+);" 'Match html unicode escapes
     .Global = True
    End With

    Set matches = regEx.Execute(sText)

    'Iterate over matches
    For Each match in matches
        'For each unicode match, replace the whole match, with the ChrW of the digits.

        sText = Replace(sText, match.Value, ChrW(match.SubMatches(0)))
    Next

    HTMLDecode = sText
End Function
票数 3
EN

Stack Overflow用户

发布于 2017-03-10 18:30:49

我基于C.Ross上面的回答和其他人制作的fb_app.inc的一些代码来做这件事。它应该能做到这一点。

代码语言:javascript
运行
AI代码解释
复制
    <%
    Option Explicit

    Dim objHelper
    Set objHelper = New HtmlEntityToUnicode

    Response.Write(objHelper.HtmlDecode("<br/><br/>hi  &#128154; green heart! purple heart &#128156; ! "))

    Set objHelper = Nothing

    Class HtmlEntityToUnicode
    dim BITS_TO_A_BYTE 
    dim BYTES_TO_A_WORD 
    dim BITS_TO_A_WORD 
    Dim m_lOnBits(30)
    Dim m_l2Power(30)

    Sub Class_Initialize()


        BITS_TO_A_BYTE = 8
        BYTES_TO_A_WORD = 4
        BITS_TO_A_WORD = 32

        m_lOnBits(0) = CLng(1)
        m_lOnBits(1) = CLng(3)
        m_lOnBits(2) = CLng(7)
        m_lOnBits(3) = CLng(15)
        m_lOnBits(4) = CLng(31)
        m_lOnBits(5) = CLng(63)
        m_lOnBits(6) = CLng(127)
        m_lOnBits(7) = CLng(255)
        m_lOnBits(8) = CLng(511)
        m_lOnBits(9) = CLng(1023)
        m_lOnBits(10) = CLng(2047)
        m_lOnBits(11) = CLng(4095)
        m_lOnBits(12) = CLng(8191)
        m_lOnBits(13) = CLng(16383)
        m_lOnBits(14) = CLng(32767)
        m_lOnBits(15) = CLng(65535)
        m_lOnBits(16) = CLng(131071)
        m_lOnBits(17) = CLng(262143)
        m_lOnBits(18) = CLng(524287)
        m_lOnBits(19) = CLng(1048575)
        m_lOnBits(20) = CLng(2097151)
        m_lOnBits(21) = CLng(4194303)
        m_lOnBits(22) = CLng(8388607)
        m_lOnBits(23) = CLng(16777215)
        m_lOnBits(24) = CLng(33554431)
        m_lOnBits(25) = CLng(67108863)
        m_lOnBits(26) = CLng(134217727)
        m_lOnBits(27) = CLng(268435455)
        m_lOnBits(28) = CLng(536870911)
        m_lOnBits(29) = CLng(1073741823)
        m_lOnBits(30) = CLng(2147483647)

        m_l2Power(0) = CLng(1)
        m_l2Power(1) = CLng(2)
        m_l2Power(2) = CLng(4)
        m_l2Power(3) = CLng(8)
        m_l2Power(4) = CLng(16)
        m_l2Power(5) = CLng(32)
        m_l2Power(6) = CLng(64)
        m_l2Power(7) = CLng(128)
        m_l2Power(8) = CLng(256)
        m_l2Power(9) = CLng(512)
        m_l2Power(10) = CLng(1024)
        m_l2Power(11) = CLng(2048)
        m_l2Power(12) = CLng(4096)
        m_l2Power(13) = CLng(8192)
        m_l2Power(14) = CLng(16384)
        m_l2Power(15) = CLng(32768)
        m_l2Power(16) = CLng(65536)
        m_l2Power(17) = CLng(131072)
        m_l2Power(18) = CLng(262144)
        m_l2Power(19) = CLng(524288)
        m_l2Power(20) = CLng(1048576)
        m_l2Power(21) = CLng(2097152)
        m_l2Power(22) = CLng(4194304)
        m_l2Power(23) = CLng(8388608)
        m_l2Power(24) = CLng(16777216)
        m_l2Power(25) = CLng(33554432)
        m_l2Power(26) = CLng(67108864)
        m_l2Power(27) = CLng(134217728)
        m_l2Power(28) = CLng(268435456)
        m_l2Power(29) = CLng(536870912)
        m_l2Power(30) = CLng(1073741824)

    End Sub

    Public Function HTMLDecode(sText)
        Dim regEx
        Dim matches
        Dim match
        sText = Replace(sText, "&quot;", Chr(34))
        sText = Replace(sText, "&lt;"  , Chr(60))
        sText = Replace(sText, "&gt;"  , Chr(62))
        sText = Replace(sText, "&amp;" , Chr(38))
        sText = Replace(sText, "&nbsp;", Chr(32))


        Set regEx= New RegExp

        With regEx
         .Pattern = "&#(\d+);" 'Match html unicode escapes
         .Global = True
        End With

        Set matches = regEx.Execute(sText)

        'Iterate over matches
        For Each match in matches
        'For each unicode match, replace the whole match, with the ChrW of the digits.
            sText = Replace(sText, match.Value, "\U"&WordToHex(match.SubMatches(0)))
        Next

        HTMLDecode = sText
    End Function


    Private Function WordToHex(lValue)
        Dim lByte
        Dim lCount

        For lCount = 0 To 3
            lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
             WordToHex = Right("0" & Hex(lByte), 2) & WordToHex 
        Next
    End Function

    Private Function RShift(lValue, iShiftBits)
        If iShiftBits = 0 Then
            RShift = lValue
            Exit Function
        ElseIf iShiftBits = 31 Then
            If lValue And &H80000000 Then
                RShift = 1
            Else
                RShift = 0
            End If
            Exit Function
        ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
            Err.Raise 6
        End If

        RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)

        If (lValue And &H80000000) Then
            RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
        End If
    End Function

    End Class


    %>
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6115708

复制
相关文章
JPA关联关系表中加其他字段
JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体[对象持久化]到数据库中。 Sun引入新的JPA ORM规范出于两个原因:其一,简化现有Java EE和Java SE应用开发工作;其二,Sun希望整合ORM技术,实现天下归一。(出自百度百科) JPA优点:上手快,使用简单。 JPA缺点:不适合关联关系复杂的项目。
用户5166330
2020/02/13
4.5K1
MySQL表与表之间的关系
这是一个书和出版社的一个例子,书要关联出版社(多个书可以是一个出版社,一个出版社也可以有好多书)。
星哥玩云
2022/08/18
3.6K0
MySQL表与表之间的关系
MySQL表与表之间的关系详解
员工信息表有三个字段:工号 姓名 部门 如何把他们相互联系起来呢??
全栈程序员站长
2022/07/21
2K0
表与表之间关系
可以在数据库图表中的表之间创建关系,以显示一个表中的列与另一个表中的列是如何相链接的。
星哥玩云
2022/09/15
1.4K0
表与表之间关系
SQL表之间的关系
要在表之间强制执行引用完整性,可以定义外键。修改包含外键约束的表时,将检查外键约束。
用户7741497
2022/06/06
2.5K0
探秘Oracle表空间、用户、表之间的关系
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huyuyang6688/article/details/49282199
DannyHoo
2018/09/13
2.7K0
探秘Oracle表空间、用户、表之间的关系
PowerBI建模表与表关系
各位表哥表姐、表弟表妹们,我们生活一个表的世界,大家可能每天都在跟表格打交道,我们这节就来重新认识表这个家族。
公众号PowerBI大师
2019/08/07
4K0
PowerBI建模表与表关系
Laravel Migrate修改表和创建表
php artisan make:migration create_table_test –table=test_a 修改表 Schema::table(‘test’, function (Blueprint $table) { $table->dropColumn([‘data’]); $table->renameColumn(‘tttt’,’test’); $table->addColumn(‘string’,’t_id’, [‘length’ => 200]); }); php artisan
苦咖啡
2018/04/28
2K0
为什么我的两个表建立数据关系有问题?
小勤:真的嘢!里面有两个小米,一个是宏仁生产的,一个是德昌生产的。但是,产品名称重复不行吗?
大海Power
2021/08/30
1.2K0
[操作系统]具有快表的内存转换机构
基本地址转换机构:一组硬件机构,将逻辑地址转换成物理地址,需要两次访存,先查页表再查内存 具有快表的地址转换机构 1)局部性原理 2)什么是快表 3)引入快表后,地址转换只需要一次访存
唯一Chat
2021/01/02
7820
laravel 表迁移报错[通俗易懂]
解决: 索引长度 & Mysql / MariaDB Laravel 默认使用 utf8mb4 编码,它支持在数据库中储存 emojis 。如果你是在版本低于 5.7.7 的 MySQL 或者版本低于 10.2.2 的 MariaDB 上创建索引,那你就需要手动配置数据库迁移的默认字符串长度。 即在 AppServiceProvider 中调用 Schema::defaultStringLength 方法来配置它:
全栈程序员站长
2022/08/09
5770
ABAP 取两个内表的交集 比较两个内表的不同
SAP自带的函数: CTVB_COMPARE_TABLES和BKK_COMPARE_TABLES; 似乎可以比较两个内表,得出第二个内表不同于第一个内表的部分(新增/删除了那些部分) 但是,具体的使用,还请有经验的朋友不吝赐教啊! 因为,我在测试数据时,发现这两个函数的效果不那么简单。 如果上述函数确实可以,提取两个内表不同部分,则我可以据此做两次比较,得到两个内表的交集。 所以,我先用另外一种方式解决了-自己写了一个提取两个内表交集的函数,供大家检阅: *" IMPORTING *" VALUE(ITAB1) TYPE INDEX TABLE *" VALUE(ITAB2) TYPE INDEX TABLE *" EXPORTING *" VALUE(ITABSAME) TYPE INDEX TABLE *"---------------------------------------------------------------------- field-symbols: <S1>, <S2>. data: L1 type i, L2 type i. assign local copy of initial line of: ITAB1 to <S1>, ITAB2 to <S2>. describe: table ITAB1 lines L1, table ITAB2 lines L2. "对记录行数少的内表,执行第一层循环; "在第二层循环中,找到对应记录,即可追加到结果内表; "同时退出第二层循环,继续执行第一层循环的下一行 IF L1 <= L2. LOOP AT ITAB1 INTO <S1>. LOOP AT ITAB2 INTO <S2>. IF <S1> EQ <S2>. APPEND <S1> TO ITABSAME. EXIT. ENDIF. ENDLOOP. ENDLOOP. ELSE. LOOP AT ITAB2 INTO <S2>. LOOP AT ITAB1 INTO <S1>. IF <S1> EQ <S2>. APPEND <S2> TO ITABSAME. EXIT. ENDIF. ENDLOOP. ENDLOOP. ENDIF. ENDFUNCTION. 另一个问题,想请教大家,在上面代码里,第二层循环是为了找出,第一层循环的当前记录,在第二个内表里是否存在;
matinal
2020/11/26
3.1K0
用户、角色、权限表的关系(mysql)
`description` varchar(255) DEFAULT NULL,
全栈程序员站长
2022/11/10
5.8K0
用户、角色、权限表的关系(mysql)
函数周期表丨其他丨表丨DATATABLE
可能从名称上看,小伙伴差不多能猜到这个函数的用途,其作用有点类似于其他编程语言中的创建语法,可以添加新的数据。
PowerBI丨白茶
2021/08/31
3560
函数周期表丨其他丨表丨DATATABLE
Django 分表的两个方案
这个问题戳到了Django ORM的痛点,对于多数据库/分库的问题,Django提供了很好的支持,通过using和db router可以很好的完成多数据库的操作。但是说到分表的问题,就有点不那么友好了。但也不是那么难处理,只是处理起来不太优雅。
the5fire
2019/03/01
3.3K2
事实表,维度,度量,指标之间的关系
事实表:每个数据仓库都包含一个或者多个事实数据表。事实数据表可能包含业务销售数据,如销售商品所产生的数据,与软件中实际表概念一样
黄昏前黎明后
2019/09/11
2.5K0
MYSQL回顾(表关系相关)
比如有两个表,分别是书籍表和出版社表。书籍和出版社是典型的多对一关系,即一本书只能由一个出版社出版,一个出版社可以出版多本书。则书籍表应该有一个外键press_id指向出版社表的id primary key。
VV木公子
2020/02/18
5.9K0
MYSQL回顾(表关系相关)
点击加载更多

相似问题

MS Access excel公式

14

使用Excel或Access 2003合并Excel表格

10

将Excel表格链接到MS Access中的表格-使用VBScript

13

如何使用phpexcel在excel表格中插入公式

22

如何使用公式在excel表格中查找数值?

13
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档