标签: utf

Erlang中的字符串 - 我应该检查哪些库和技术?

我正在开展一个需要国际化支持的项目.我想通过UTF支持开始,我想知道在Erlang中处理UTF的最佳做法是什么?

从我目前的研究来看,似乎有一些问题与Erlang的内置字符串处理一些用例(JSON解析是一个很好的例子).

我一直在关注Starling并最近阅读(某处),它可能会作为UTF'标准'进入标准的Erlang版本.这是真的?我应该关注其他图书馆或方法吗?

来自评论:

EEP(Erlang Enhancement Proposal)10详细信息表示Erlang中的Unicode字符

string erlang utf

2
推荐指数
1
解决办法
938
查看次数

将UTF-16转换为UTF-8

我目前正在使用VC++ 2008 MFC.由于PostgreSQL不支持UTF-16(Windows用于Unicode的编码),我需要在存储之前将字符串从UTF-16转换为UTF-8.

这是我的代码片段.

// demo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "demo.h"
#include "Utils.h"
#include <iostream>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    int nRetCode = 0;

    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
        // TODO: change error code to suit your needs
        _tprintf(_T("Fatal Error: …
Run Code Online (Sandbox Code Playgroud)

c++ windows unicode winapi utf

2
推荐指数
1
解决办法
2万
查看次数

Java UTF-16编码代码

在java中将Unicode代码点(整数)编码为char数组(Bytes)的函数基本上是这样的:

return new char[] { (char) codePoint };
Run Code Online (Sandbox Code Playgroud)

这只是从整数值到char的转换.

我想知道这个演员是如何实际完成的,这个演员背后的代码是为了从一个整数值转换为一个用UTF-16编码的字符.我尝试在java源代码上寻找它,但没有运气.

java encoding utf-16 utf character-encoding

2
推荐指数
1
解决办法
3275
查看次数

需要帮助理解UTF编码

你好,我注意到当我使用UTF-8编码(没有BOM)保存文本文件时,我能够在C#上使用UTF-16编码完美地读取它.现在这让我有点困惑,因为UTF-8只使用了8位,对吧?utf-16对每个字符都需要16位.

现在想象一下,我把这个文件中的字符串"ab"写成UTF-8,那么字母"a"有一个字节,"b"有另一个字节.

好的,但是在使用UTF-16字符集时如何读取这个UTF-8文件呢?我看到,在读取文件的方式中,"AB"的两个字节会被误认为成只有一个包含两个字节字符了.因为UTF-16需要那2个字节.

这是我读它的方式(t.txt被编码为UTF-8):

using(StreamReader sr = new StreamReader(File.OpenRead("t.txt"), Encoding.GetEncoding("utf-16")))
{
    Console.Write(sr.ReadToEnd());
    Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)

c# encoding utf-8 utf-16 utf

2
推荐指数
1
解决办法
673
查看次数

Python将字符串保存到文件.Unicode错误

我正在使用Python中的Spreadsheet API从Google电子表格中提取数据.我可以使用for循环在命令行上打印我的电子表格的每一行,但是一些文本包含符号,例如摄氏度符号(小圆圈).当我在命令行上打印这些行时,我想将它们写入文件.但是当我这样做时,我得到了不同的unicode错误.我尝试手动解决它,但有太多:

current=current.replace(u'\xa0',u'')
current=current.replace(u'\u000a',u'p')
current=current.replace(u'\u201c',u'\"')
current=current.replace(u'\u201d',u'\"')
current=current.replace(u'\u2014',u'-')
Run Code Online (Sandbox Code Playgroud)

我该怎么办才能得到错误?例如

UnicodeEncodeError:'ascii'编解码器无法对位置1394中的字符u'\ xa0'进行编码:序数不在范围内(128)

current=current.replace(u'\u0446',u'u')
Run Code Online (Sandbox Code Playgroud)

python unicode ascii utf

2
推荐指数
1
解决办法
3906
查看次数

utf8表示为普通文本

$text = "\xd0\xa2\xd0\xb0\xd0\xb9\xd0\xbd\xd0\xb0";
$text = iconv('UTF-8', 'UTF-8//IGNORE', $text);
var_dump($text); //????? - good
$text = file_get_contents('log.txt');
$text = iconv('UTF-8', 'UTF-8//IGNORE', trim($text));
var_dump($text); // \xd0\xa2\xd0\xb0\xd0\xb9\xd0\xbd\xd0\xb0 - bad
Run Code Online (Sandbox Code Playgroud)

为什么如果\xd0\xa2\xd0\xb0\xd0\xb9\xd0\xbd\xd0\xb0从文件中读取字符串iconv不起作用以及如何解决它?

php utf-8 utf

2
推荐指数
1
解决办法
595
查看次数

UnicodeDecodeError:'ascii'编解码器无法解码位置47的字节0x92:序号不在范围内(128)

我正在尝试使用Python在StringIO对象中写入数据,然后最终使用psycopg2的copy_from()函数将此数据加载到postgres数据库中.

首先,当我这样做时,copy_from()抛出一个错误:错误:编码"UTF8"的无效字节序列:0xc92所以我遵循了这个问题.

我发现我的Postgres数据库有UTF8编码.

我正在编写数据的文件/ StringIO对象显示其编码如下:setgid非ISO扩展ASCII英文文本,带有很长的行,带有CRLF行终止符

我试图将我写入中间文件/ StringIO对象的每个字符串编码为UTF8格式.要做到这一点,每个字符串使用.encode(encoding ='UTF-8',errors ='strict')).

这是我现在得到的错误:UnicodeDecodeError:'ascii'编解码器无法解码位置47的字节0x92:序号不在范围内(128)

这是什么意思?我如何解决它?

编辑:我正在使用Python 2.7我的一些代码:

我从MySQL数据库中读取了根据MySQL Workbench以UTF-8编码的数据.这是用于将我的数据(从MySQL db获得)写入StringIO对象的几行代码:

# Populate the table_data variable with rows delimited by \n and columns delimited by \t
row_num=0
for row in cursor.fetchall() :

    # Separate rows in a table by new line delimiter
    if(row_num!=0):
        table_data.write("\n")

    col_num=0
    for cell in row:    
        # Separate cells in a row by tab delimiter
        if(col_num!=0):
            table_data.write("\t") 

        table_data.write(cell.encode(encoding='UTF-8',errors='strict'))
        col_num = col_num+1

    row_num = row_num+1   
Run Code Online (Sandbox Code Playgroud)

这是从我的StringIO对象table_data写入Postgres数据库的代码:

cursor = db_connection.cursor()
cursor.copy_from(table_data, <postgres_table_name>)
Run Code Online (Sandbox Code Playgroud)

python postgresql encoding utf python-2.7

2
推荐指数
1
解决办法
2万
查看次数

什么是代理对?

我在一个javascript开源项目中遇到了这段代码.

validator.isLength = function (str, min, max) 
    // match surrogate pairs in string or declare an empty array if none found in string
    var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
    // subtract the surrogate pairs string length from main string length
    var len = str.length - surrogatePairs.length;
    // now compare string length with min and max ... also make sure max is defined(in other words, max param is optional for function)
    return len >= min && (typeof max === 'undefined' || …
Run Code Online (Sandbox Code Playgroud)

javascript string encoding utf string-length

2
推荐指数
2
解决办法
4080
查看次数

XML文件中的UTF-8与UTF8

XML文件中的正确UTF8编码声明是什么?我见过两者.

<?xml version="1.0" encoding="UTF-8"?>
...
Run Code Online (Sandbox Code Playgroud)

要么

<?xml version="1.0" encoding="UTF8"?>
...
Run Code Online (Sandbox Code Playgroud)

xml utf-8 utf

2
推荐指数
1
解决办法
1049
查看次数

将Unicode代码点转换为UTF-8和UTF-32

我想不出一种方法来删除前导零.我的目标是for循环,然后创建每个数字的UTF-8和UTF-32版本.

例如,使用UTF-8不是必须删除前导零?有没有人有解决方案如何解决这个问题?基本上我要问的是:有人有一个简单的解决方案将Unicode代码点转换为UTF-8吗?

    for (i = 0x0; i < 0xffff; i++) {
        printf("%#x \n", i);
        //convert to UTF8
    }
Run Code Online (Sandbox Code Playgroud)

所以这里是我想要为每个人完成的一个例子i.

  • 例如:Unicode值U + 0760(Base 16)将转换为UTF8 as
    • 二进制:1101 1101 1010 0000
    • 十六进制:DD A0

基本上我试图这样做,每个i都将它转换为UTF-8中的十六进制等效.

我遇到的问题似乎是将Unicode转换为UTF-8的过程涉及从位数中删除前导0.我不确定如何动态地做到这一点.

c utf-8 utf

2
推荐指数
1
解决办法
4011
查看次数