Classic ASP - How to convert a UTF-8 string to UTF-16?

后端 未结 2 1155
时光说笑
时光说笑 2020-12-12 06:33

I know there is already have post: Classic ASP - How to convert a UTF-8 string to UCS-2?

But my situation another.
I want convert UTF-8 to UCS-2BE.
For ex

相关标签:
2条回答
  • 2020-12-12 06:43

    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.

    In web development encoding is intrinsically linked to

    The source encoding you use to save the web page

    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.

    Take for example your PHP snippet

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

    This will work providing the following is true

    • 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">
      

      or by specifying a HTTP Content-Type Header


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

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

    • 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"
      %>
      

    UPDATE:

    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

    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.

    Links

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

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

    0 讨论(0)
  • 2020-12-12 06:49

    in kannel.conf in section SMSC add alt-charset = UCS-2 (or UCS-2BE) thats enough. Kannel well send to smsc in this charset.

    0 讨论(0)
提交回复
热议问题