经典 ASP - 如何将 UTF-8 字符串转换为 UTF-16? [英] Classic ASP - How to convert a UTF-8 string to UTF-16?

查看:16
本文介绍了经典 ASP - 如何将 UTF-8 字符串转换为 UTF-16?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道已经有帖子:经典 ASP - 如何将 UTF-8 字符串转换为 UCS-2?

但我的情况不同.
我想将 UTF-8 转换为 UCS-2BE.
例如,UTF-8 格式的Мухтарам Мизоч"文本转换为CEB0@0<87>G".

But my situation another.
I want convert UTF-8 to UCS-2BE.
For example this text in UTF-8 "Мухтарам Мизоч" convert to this "CEB0@0<� 87>G".

例如在 PHP 中我可以使用准备好的函数 iconv("utf-8","ucs-2be","Мухтарам Мизоч");
但是在经典的 ASP 中不能找到任何解决方案.
此解决方案需要通过 Kannel 发送 Unicode SMS 文本.

For example in PHP i can use ready function iconv("utf-8","ucs-2be","Мухтарам Мизоч");
But in classical ASP can't find any solution.
This solution need for send Unicode SMS text via Kannel.

推荐答案

很讨厌回答这个问题,但我感到有动力,因为你已经做出了许多人在使用 ASP、PHP 或其他方式进行编码时的普遍假设您使用的语言.

So sick of answering this question, but I feel impelled to as you have made a common assumption that many make when it comes to encoding in ASP, PHP or whatever language you are using.

在网络开发中,编码与

您用于保存网页的源编码

只看 iconv 参考 下的评论让我发笑同时很伤心,因为有很多人不理解这个话题.

Just looking at the comments under the iconv reference made me laugh and sad at the same time because there are so many people out there who don't understand this topic.

以您的 PHP 片段为例

Take for example your PHP snippet

iconv("utf-8","ucs-2be","Мухтарам Мизоч");

只要满足以下条件,这将起作用

This will work providing the following is true

  • 页面作者使用 UTF-8 编码保存文件(大多数现代编辑器都以某种形式或形式提供此选项).
  • 客户端 Internet 浏览器知道它应该通过 HTML 中的元标记将页面作为 UTF-8 处理,

  • The page author saved the file using UTF-8 encoding (Most modern editors have this option in some shape or form).
  • The client Internet Browser knows it should be handling the page as UTF-8 either via a meta tag in the HTML,

<meta http-equiv="content-type" content="text/html; charset=utf-8">

或通过指定 HTTP Content-Type 标头

or by specifying a HTTP Content-Type Header

就经典 ASP 而言,您需要这样做;

In terms of Classic ASP it is the same you need to;

  • 确保页面保存为 UTF-8 编码,这包括所有作为依赖项的 #include 文件.

  • Make sure the page is saved as UTF-8 encoding, this includes any #include files that are dependencies.

通过在页面最顶部(必须是第一行)指定此预处理指令,告诉 IIS 您的页面是 UTF-8.

Tell IIS that your pages are UTF-8 by specifying this pre-processing instruction at the very top of the page (must be the first line).

<%@Language="VBScript" CodePage = 65001 %>

  • 告诉浏览器你使用的是什么编码

  • Tell the browser what encoding you are using

    <%
    'Tell server to send all strings back to the client as UTF-8
    'while also setting the charset in the HTTP Content Type header.
    Responce.CodePage = 65001
    Response.ContentType = "html/text"
    Response.Charset = "UTF-8"
    %>
    

  • 更新:

    UCS-2 (UTF-16 LE) 或 UCS-2BE (UTF-16 BE) 受经典 ASP 支持,指定 CodePage(1200 或 1201)将导致;

    Neither UCS-2 (UTF-16 LE) or UCS-2BE (UTF-16 BE) are supported by Classic ASP, specifying either CodePage (1200 or 1201) will result in;

    ASP 0203 - Invalid CodePage Value

    在阅读了一些有关 Kannel 的信息后,您似乎可以控制发送到 SMS 网关的字符集,我建议您尝试使用 UTF-8 发送它.

    After reading a bit about Kannel it does appear as though you can control the character set you send to the SMS gateway, I would recommend you try to send it using UTF-8.

    链接

    • Sending arabic SMS in kannel (This question is about sending arabic SMS using Java to Kannel but the information is relevant).

    Windows XP 上的 Unicode(虽然针对的是 Windows XP代码页信息仍然相关).

    Unicode on Windows XP (Although aimed at Windows XP the codepage information is still relevant).

    这篇关于经典 ASP - 如何将 UTF-8 字符串转换为 UTF-16?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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