精华内容
下载资源
问答
  • 实现从中文UTF-8(两种格式的转换)-------------------------------------------import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;class TransformToChinese{public...

    从网上找的,加入了屏幕读写功能。实现从中文到UTF-8(两种格式的转换)

    -------------------------------------------

    import java.io.BufferedReader;

    import java.io.IOException;

    import java.io.InputStreamReader;

    class TransformToChinese

    {

    public static String GBK2Unicode(String str){

    StringBuffer result = new StringBuffer();

    for (int i = 0; i < str.length(); i++){

    char chr1 = (char)str.charAt(i);

    if(!isNeedConvert(chr1)){

    result.append(chr1);

    continue;

    }

    result.append("\\u" + Integer.toHexString((int)chr1));

    }

    return result.toString();

    }

    public static boolean isNeedConvert(char para){

    return ((para&(0x00FF))!=para);

    }

    public static String GBK2Unicode2(String str){

    StringBuffer result = new StringBuffer();

    for (int i = 0; i < str.length(); i++){

    char chr1 = (char)str.charAt(i);

    result.append("" + Integer.toString((int)chr1)+ ";");

    }

    return result.toString();

    }

    public static void main(String[] args) throws IOException{

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    String str=br.readLine();

    System.out.println(GBK2Unicode(str));

    System.out.println(GBK2Unicode2(str));

    }

    }

    输入 : “输入”

    输出:

    \u8f93\u5165

    输入

    展开全文
  • 在 HTML 中,中文的“好好学习”可以表示为“好好学习”在项目中,需要对接短信告警,短信告警返回数据要求是utf8的后来继续沟通,才发现要的是html-utf8的;没有找到合适的golang工具包,涉及语言转码的包主要有...

    在 HTML 中,中文的“好好学习”可以表示为“好好学习”

    在项目中,需要对接短信告警,短信告警返回数据要求是utf8的

    后来继续沟通,才发现要的是html-utf8

    的;

    没有找到合适的golang工具包,涉及语言转码的包主要有

    mahonia,支持各种格式的数据转换,gbk,utf8,gb2312

    net/html,支持网页转码,改的是转换网页中的,&,',',.

    根据网上经验,提供三个版本的转换:

    Javascript

    function ConvUtf8(obj) {

    returnobj.replace(/[^\u0000-\u00FF]/g,function($0) {returnescape($0).replace(/(%u)(\w{4})/gi, "$2;") });

    }

    JAVA

    public static String UTF8_html_conv(String str){

    StringBuffer stbPreemptionArg = new StringBuffer();

    for(int i = 0;i

    if (str.codePointAt(i) > 255){

    stbPreemptionArg.append(""+Integer.toString(str.charAt(i), 16)+";");

    }else{

    stbPreemptionArg.append(str.charAt(i));

    }

    }

    return stbPreemptionArg.toString();

    }

    Golang

    func CovertToHtml(src string) string{

    rs := []rune(src)

    htmlUtf8 := ""

    for _, r := range rs {

    rint := int(r)

    if rint

    展开全文
  • Unicode(UTF8)class qswhGBK{var $qswhData;function qswhGBK($filename=”qswhGBK.php”){$this->qswhData=file($filename);}function gb2u($gb,$callback=””){/******(qiushuiwuhen 2002-8-15)...

    //php汉字转码 GBK->Unicode(UTF8)

    class qswhGBK{

    var $qswhData;

    function qswhGBK($filename=”qswhGBK.php”){

    $this->qswhData=file($filename);

    }

    function gb2u($gb,$callback=””){

    /******(qiushuiwuhen 2002-8-15)******/

    $ret=””;

    for($i=0;$i

    if(($p=ord(substr($gb,$i,1)))>127){

    $q=ord(substr($gb,++$i,1));

    $q=($q-($q>128?65:64))*4;

    $q=substr($this->qswhData[$p-128],$q,4);

    }

    else

    $q=dechex($p);

    if(empty($callback))

    $ret.=$q;

    else {

    $arr=array(“htmlHex”,”htmlDec”,”escape”,”u2utf8″);

    if(is_integer($callback)){

    if($callback>count($arr))die(“Invalid Function”);

    $ret.=$this->$arr[$callback-1]($q);

    }else

    $ret.=$callback($q);

    }

    }

    return $ret;

    }

    function htmlHex($str){

    return “”.$str.”;”;

    } // 程序员之家 bbs.it-home.org

    function htmlDec($str){

    return “”.hexdec($str).”;”;

    }

    function escape($str){

    return hexdec($str)<256?chr(hexdec($str)):"%u".$str;

    }

    function u2utf8($str){

    /******(qiushuiwuhen 2002-8-15)******/

    $sp=”!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~”;

    $dec=hexdec($str);

    $bin=decbin($dec);

    $len=strlen($bin);

    $arr=array(“c0″,”e0″,”f0”);

    if($dec>0x7f){

    $ret=””;

    for($i=$len,$j=-1;$i>=0;$i-=6,$j++){

    if($i>6)

    $ret=”%”.dechex(0x80+bindec(substr($bin,$i-6,6))).$ret;

    else

    $ret=”%”.dechex(hexdec($arr[$j])+bindec(substr($bin,0,6-$i))).$ret;

    }

    }else{

    if(strpos($sp,chr($dec)))

    $ret=chr($dec);

    else

    $ret=”%”.strtolower($str);

    }

    return $ret;

    }

    }

    256?chr(hexdec($str)):"%u".$str;

    展开全文
  • UTF8其实和Unicode是同类,就是在编码方式上不同!...而UTF8编码:一个英文字母“a” 和 一个汉字 “好”,编码后占用的空间大小就不样了,前者是一个字节,后者是三个字节!现在就让我们来看看UTF...

    UTF8其实和Unicode是同类,就是在编码方式上不同!

    首先UTF8编码后的大小是不一定,不像Unicode编码后的大小是一样的!

    我们先来看Unicode的编码:一个英文字母 “a” 和 一个汉字 “好”,编码后都是占用的空间大小是一样的,都是两个字节!

    而UTF8编码:一个英文字母“a” 和 一个汉字 “好”,编码后占用的空间大小就不样了,前者是一个字节,后者是三个字节!

    现在就让我们来看看UTF8编码的原理吧:

    因为一个字母还有一些键盘上的符号加起来只用二进制七位就可以表示出来,而一个字节就是八位,所以UTF8就用一个字节来表式字母和一些键盘上的符号。然而当我们拿到被编码后的一个字节后怎么知道它的组成?它有可能是英文字母的一个字节,也有可能是汉字的三个字节中的一个字节!所以,UTF8是有标志位的!

    当要表示的内容是 7位 的时候就用一个字节:0******* 第一个0为标志位,剩下的空间正好可以表示ASCII 0-127 的内容。

    当要表示的内容在 8 到 11 位的时候就用两个字节:110***** 10****** 第一个字节的110和第二个字节的10为标志位。

    当要表示的内容在 12 到 16 位的时候就用三个字节:1110***** 10****** 10****** 和上面一样,第一个字节的1110和第二、三个字节的10都是标志位,剩下的占湔?每梢员硎竞鹤帧?BR>

    以此类推:

    四个字节:11110**** 10****** 10****** 10******

    五个字节:111110*** 10****** 10****** 10****** 10******

    六个字节:1111110** 10****** 10****** 10****** 10****** 10******

    UTF-7:A Mail-Safe Transformation Format of Unicode(RFC1642)。这是一种使用 7 位 ASCII 码对 Unicode 码进行转换的编码。它的设计目的仍然是为了在只能传递 7 为编码的邮件网关中传递信息。 UTF-7 对英语字母、数字和常见符号直接显示,而对其他符号用修正的 Base64 编码。符号 + 和 - 号控制编码过程的开始和暂停。所以乱码中如果夹有英文单词,并且相伴有 + 号和 - 号,这就有可能是 UTF-7 编码。

    关于UTF7的更多资料如下(都是英语的,如果想具体了解再看):

    UTF-7

    A Mail-Safe Transformation Format of Unicode

    Status of this Memo

    This memo provides information for the Internet community. This memo

    does not specify an Internet standard of any kind. Distribution of

    this memo is unlimited.

    Abstract

    The Unicode Standard, version 2.0, and ISO/IEC 10646-1:1993(E) (as

    amended) jointly define a character set (hereafter referred to as

    Unicode) which encompasses most of the world's writing systems.

    However, Internet mail (STD 11, RFC 822) currently supports only 7-

    bit US ASCII as a character set. MIME (RFC 2045 through 2049) extends

    Internet mail to support different media types and character sets,

    and thus could support Unicode in mail messages. MIME neither defines

    Unicode as a permitted character set nor specifies how it would be

    encoded, although it does provide for the registration of additional

    character sets over time.

    This document describes a transformation format of Unicode that

    contains only 7-bit ASCII octets and is intended to be readable by

    humans in the limiting case that the document consists of characters

    from the US-ASCII repertoire. It also specifies how this

    transformation format is used in the context of MIME and RFC 1641,

    "Using Unicode with MIME".

    Motivation

    Although other transformation formats of Unicode exist and could

    conceivably be used in this context (most notably UTF-8, also known

    as UTF-2 or UTF-FSS), they suffer the disadvantage that they use

    octets in the range decimal 128 through 255 to encode Unicode

    characters outside the US-ASCII range. Thus, in the context of mail,

    those octets must themselves be encoded. This requires putting text

    through two successive encoding processes, and leads to a significant

    expansion of characters outside the US-ASCII range, putting non-

    English speakers at a disadvantage. For example, using UTF-8 together

    with the Quoted-Printable content transfer encoding of MIME

    represents US-ASCII characters in one octet, but other characters may

    require up to nine octets.

    Overview

    UTF-7 encodes Unicode characters as US-ASCII octets, together with

    shift sequences to encode characters outside that range. For this

    purpose, one of the characters in the US-ASCII repertoire is reserved

    for use as a shift character.

    Many mail gateways and systems cannot handle the entire US-ASCII

    character set (those based on EBCDIC, for example), and so UTF-7

    contains provisions for encoding characters within US-ASCII in a way

    that all mail systems can accomodate.

    UTF-7 should normally be used only in the context of 7 bit

    transports, such as mail. In other contexts, straight Unicode or

    UTF-8 is preferred.

    See RFC 1641, "Using Unicode with MIME" for the overall specification

    on usage of Unicode transformation formats with MIME.

    Definitions

    First, the definition of Unicode:

    The 16 bit character set Unicode is defined by "The Unicode

    Standard, Version 2.0". This character set is identical with the

    character repertoire and coding of the international standard

    ISO/IEC 10646-1:1993(E); Coded Representation Form=UCS-2;

    Subset=300; Implementation Level=3, including the first 7

    amendments to 10646 plus editorial corrections.

    Note. Unicode 2.0 further specifies the use and interaction of

    these character codes beyond the ISO standard. However, any valid

    10646 sequence is a valid Unicode sequence, and vice versa;

    Unicode supplies interpretations of sequences on which the ISO

    standard is silent as to interpretation.

    Next, some handy definitions of US-ASCII character subsets:

    Set D (directly encoded characters) consists of the following

    characters (derived from RFC 1521, Appendix B, which no longer

    appears in RFC 2045): the upper and lower case letters A through Z

    and a through z, the 10 digits 0-9, and the following nine special

    characters (note that "+" and "=" are omitted):

    Character ASCII & Unicode Value (decimal)

    ' 39

    ( 40

    ) 41

    , 44

    - 45

    . 46

    / 47

    : 58

    ? 63

    Set O (optional direct characters) consists of the following

    characters (note that "\" and "~" are omitted):

    Character ASCII & Unicode Value (decimal)

    ! 33

    " 34

    # 35

    $ 36

    % 37

    & 38

    * 42

    ; 59

    < 60

    = 61

    > 62

    @ 64

    [ 91

    ] 93

    ^ 94

    _ 95

    ' 96

    { 123

    | 124

    } 125

    Rationale. The characters "\" and "~" are omitted because they are

    often redefined in variants of ASCII.

    Set B (Modified Base 64) is the set of characters in the Base64

    alphabet defined in RFC 2045, excluding the pad character "="

    (decimal value 61).

    Rationale. The pad character = is excluded because UTF-7 is designed

    for use within header fields as set forth in RFC 2047. Since the only

    readable encoding in RFC 2047 is "Q" (based on RFC 2045's Quoted-

    Printable), the "=" character is not available for use (without a lot

    of escape sequences). This was very unfortunate but unavoidable. The

    "=" character could otherwise have been used as the UTF-7 escape

    character as well (rather than using "+").

    Note that all characters in US-ASCII have the same value in Unicode

    when zero-extended to 16 bits.

    UTF-7 Definition

    A UTF-7 stream represents 16-bit Unicode characters using 7-bit US-

    ASCII octets as follows:

    Rule 1: (direct encoding) Unicode characters in set D above may be

    encoded directly as their ASCII equivalents. Unicode characters in

    Set O may optionally be encoded directly as their ASCII

    equivalents, bearing in mind that many of these characters are

    illegal in header fields, or may not pass correctly through some

    mail gateways.

    Rule 2: (Unicode shifted encoding) Any Unicode character sequence

    may be encoded using a sequence of characters in set B, when

    preceded by the shift character "+" (US-ASCII character value

    decimal 43). The "+" signals that subsequent octets are to be

    interpreted as elements of the Modified Base64 alphabet until a

    character not in that alphabet is encountered. Such characters

    include control characters such as carriage returns and line

    feeds; thus, a Unicode shifted sequence always terminates at the

    of a line. As a special case, if the sequence terminates with the

    character "-" (US-ASCII decimal 45) then that character is

    absorbed; other terminating characters are not absorbed and are

    processed normally.

    Note that if the first character after the shifted sequence is "-"

    then an extra "-" must be present to terminate the shifted

    sequence so that the actual "-" is not itself absorbed.

    Rationale. A terminating character is necessary for cases where

    the next character after the Modified Base64 sequence is part of

    character set B or is itself the terminating character. It can

    also enhance readability by delimiting encoded sequences.

    Also as a special case, the sequence "+-" may be used to encode

    the character "+". A "+" character followed immediately by any

    character other than members of set B or "-" is an ill-formed

    sequence.

    Unicode is encoded using Modified Base64 by first converting

    Unicode 16-bit quantities to an octet stream (with the most

    significant octet first). Surrogate pairs (UTF-16) are converted

    by treating each half of the pair as a separate 16 bit quantity

    (i.e., no special treatment). Text with an odd number of octets is

    ill-formed. ISO 10646 characters outside the range addressable via

    surrogate pairs cannot be encoded.

    Rationale. ISO/IEC 10646-1:1993(E) specifies that when characters

    the UCS-2 form are serialized as octets, that the most significant

    octet appear first. This is also in keeping with common network

    practice of choosing a canonical format for transmission.

    Rationale. The policy for code point allocation within ISO 10646

    and Unicode is that the repertoires be kept synchronized. No code

    points will be allocated in ISO 10646 outside the range

    addressable by surrogate pairs.

    Next, the octet stream is encoded by applying the Base64 content

    transfer encoding algorithm as defined in RFC 2045, modified to

    omit the "=" pad character. Instead, when encoding, zero bits are

    added to pad to a Base64 character boundary. When decoding, any

    bits at the end of the Modified Base64 sequence that do not

    constitute a complete 16-bit Unicode character are discarded. If

    such discarded bits are non-zero the sequence is ill-formed.

    Rationale. The pad character "=" is not used when encoding

    Modified Base64 because of the conflict with its use as an escape

    character for the Q content transfer encoding in RFC 2047 header

    fields, as mentioned above.

    Rule 3: The space (decimal 32), tab (decimal 9), carriage return

    (decimal 13), and line feed (decimal 10) characters may be

    directly represented by their ASCII equivalents. However, note

    that MIME content transfer encodings have rules concerning the use

    of such characters. Usage that does not conform to the

    restrictions of RFC 822, for example, would have to be encoded

    using MIME content transfer encodings other than 7bit or 8bit,

    such as quoted-printable, binary, or base64.

    Given this set of rules, Unicode characters which may be encoded via

    rules 1 or 3 take one octet per character, and other Unicode

    characters are encoded on average with 2 2/3 octets per character

    plus one octet to switch into Modified Base64 and an optional octet

    to switch out.

    Example. The Unicode sequence "A."

    (hexadecimal 0041,2262,0391,002E) may be encoded as follows:

    A+ImIDkQ.

    Example. The Unicode sequence "Hi Mom --!"

    (hexadecimal 0048, 0069, 0020, 004D, 006F, 006D, 0020, 002D, 263A,

    002D, 0021) may be encoded as follows:

    Hi Mom -+Jjo--!

    Example. The Unicode sequence representing the Han characters for

    the Japanese word "nihongo" (hexadecimal 65E5,672C,8A9E) may be

    encoded as follows:

    +ZeVnLIqe-

    取消

    评论

    展开全文
  • 1、修改数据库配置文件/etc/my.cnf ...alter database 库名 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; 3、修改表 alter table 表名 convert to character set utf8mb4 COLLATE utf8mb4_general_ci;
  • 【问题】在数据迁移过程中,原数据字段是Blob类型需转换为CLOB,直接使用dbms_lob.converttoclob 转换后 发现字符格式UTF16不对 【分析】分析程序... 那么很明显需要做UTF16到UTF8转换具体Oracle字符集参考http://...
  • php的汉字转换一直是比较麻烦的事该类内置了四个函数"htmlHex","htmlDec","escape","u2utf8"方便用户的使用,同时也可自定义函数进行自己喜欢的操作qswhGBK.php 从这里下载...function qswhGBK($fil...
  • then · · · identifyformat $FILEFORMAT #· · · echo "This file format is :"$FORMAT · · · echo "iconv -f $FORMAT -t utf8 $filename -o ${filename%.*}.bak" · · · iconv -f $FORMAT -...
  • 展开全部java中怎么把utf-8编码的字符串转成汉字如果确实e5a48de588b63231313335323631343130323136353331333361313964报错,下面我写的一个例子,你可以看一下。importjava.io.FileInputStream;importjava.io....
  • 背景:某个系统的mysql数据库dnname采用默认的latin1字符集,系统升级需要将所有数据转换成utf-8格式,目标数据库为newdbname(建库时使用utf8)方法一:步骤一 命令行执行:mysqldump --opt -hlocalhost -uroot -p***...
  • 支付宝给出来的示例代码,里面采用的是GBK编码,使用Zend Studio打开以后中文全是乱码.我先是用写字板打开,然后拷贝到记事本中,然后再拷贝到Zend Studio中,这样就实现了将原有代码拷贝过来.我是直接使用的原有代码,...
  • java实现utf8转换ansi

    2021-03-17 10:46:40
    打开”记事本“程序 Notepad.exe,新建一个文本文件,内容就是一个”严“字,依次采用 ANSI, Unicode,Unicode big endian 和 UTF-8 编码方式保存。 然后,用文本......关于编码ansi、GB2312、unicode与utf-8的区别 先做...
  • HTML网页是有编码的,在head区域内的这句话是告诉浏览器,该网页采用的是utf-8编码,也就是简体中文编码。...前UTF-8已经把几种重要的亚洲语言纳入,包括简繁中文和日韩文字。所以在制作某些网站时...
  • 将GBK编码转换成UTF-8编码

    千次阅读 2021-03-23 21:59:36
    * 将GBK编码转换成UTF-8编码 * */ protected String gbkConvertToUtf8(String str) throws UnsupportedEncodingException { if (StringUtils.isNotBlank(str)) { //转换成gbk编码 String gbkChinese..
  • chunli@ubuntu14:~$filehaha.hhaha.h:Csource,ISO-8859text,withCRLFlineterminatorschunli@ubuntu14:~$iconv-fgbk-tutf8haha.h>derlog.hchunli@ubuntu14:~$filederlog.hderlog.h:Csource,...
  • Linux下转换windows下写的一个txt文本文件...#include #include #include #include int gbk2utf8(char *src, size_t *srclen, char *dest, size_t *destlen){iconv_t cd = iconv_open("UTF-8", "GBK");if (cd == (i...
  • /*** utf-8 转换成 unicode* @author fanhui* 2007-3-15* @param inStr* @return*/public static String utf8ToUnicode(String inStr) {char[] myBuffer = inStr.toCharArray();StringBuffer sb = new StringBuffer...
  • /** * 将unicode编码转换成汉字 * @param theString * @return */ public static String decodeUnicode(String theString) { char aChar; int len = theString.length(); StringBuffer outBuffe...
  • Unicode UTF-8 转换

    2021-01-26 07:21:35
    Unicode是类似“U+4E25”或“\u4E25”的编码方式,很多情况下是4个十六进制的数,有时候不止。...Unicode的实现方式称为Unicode转换格式(Unicode Transformation Format,简称为UTF),UTF-8(8-bi...
  • 因为项目的需要linux下将GBK编码转换utf8编码,google一下,网上的相关资源比较少,下面的操作经过本人的反复试验。本例子同样适用于其他的编码转换。有gbk到u因为项目的需要linux下将GBK编码转换utf8编码,...
  • 在HTML中,中文的“好好学习”可以表示为“好好学习”在项目中,需要对接短信告警,短信告警返回数据要求是utf8的后来继续沟通,才发现要的是html-utf8 的;没有找到合适的golang工具包,涉及语言转码的包主要有...
  • ASCII及中文转UTF8工具

    2021-05-23 10:46:48
    ASCII及中文转UTF8工具是一款支持将ASII编码、中文转换成为UTF8格式的工具;它也是在进行物联网进行短信发送的时候需要进行使用到的,只要转换成功,就能将信息发送到用户的手机上;软件的使用简单,直观整洁灵活...
  • java中GBK转UTF-8乱码的解决方法如果自己采用的是GBK编码,对方采用得到是UTF-8编码,发送数据时需要将GBK编码数据转换成UTF-8编码数据,这样对方才不会乱码。问题出现:GBK转UTF-8时,奇数个中文会乱码,偶数个中文...
  • 遇到这样的问题,明明全部系统都以utf-8设置,但是用phpmyadmin去看资料库时,发现中文字仍然是乱码。若有发生这种情况,是因为虽然mysql本身及网页都是utf-8,但是xoops却用latin1将数据传给mysql,因此最后是utf-8...
  • 我使用了iconv和mb_convert_encoding两个函数都试了,然后发现结果是一样的,都会出现各种问题,不是哪里少字了就是直接错误,请问大神怎么解决啊回复讨论(解决方案)iconv("GB2312","UTF-8//IGNORE",$data)确定 原...
  • 展开全部Java 中内核是32313133353236313431303231363533e4b893e5b19e31333335336436 unicode,...所以你这句话中的“Java中如果自身是 utf8" 这段是没有意义的。一个 String 字符串不存在字符集概念,只有把一个 S...
  • 迁移过程网上有很多,我今天主要想讲下字符集转换后,可能对业务产生的影响,我以GBK转换UTF8为例说明。主要有两点:1.汉字在GBK编码中占2个字节,在UTF8编码中占3个字节,而mysql的索引要求总长度不超过767个字节...
  • C语言汉字gbk转utf-8

    2021-05-21 15:48:06
    一、注意事项1.请注意汉字内码(对应字符为\xcc等)和打印出的转义字符(\\xcc)的区别!...3.我的终端是utf-8格式,对于其他编码不能显示。二、看看code1.test.c#include #include #include int code_convert(c...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 237,462
精华内容 94,984
关键字:

utf8转换成中文