标签: unicode-string

从UNICODE支持的WINAPI编程开始

我开始使用WINAPIs在C中开发应用程序.我希望我的应用程序支持UNICODE.

我正在使用gingw与gcc编译器.我应该怎么做才能使我的应用程序UNICODE支持.它应该适用于从xp开始的所有Windows版本.我希望我的申请能够在所有语言中发挥作用.

能否请你给我一些关于这个以及Do's和Dont's的指导.

c windows unicode winapi unicode-string

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

什么是std :: wifstream :: getline对我的wchar_t数组做什么?在getline返回后,它被视为一个字节数组

我想从文件中读取Unicode文本行(UTF-16 LE,换行符分隔).我正在使用Visual Studio 2012并针对32位控制台应用程序.

我无法在WinAPI中找到ReadLine功能,因此我转向Google.很明显,我不是第一个寻求这种功能的人.最常推荐的解决方案是使用std :: wifstream.

我写了类似以下的代码:

wchar_t buffer[1024];
std::wifstream input(L"input.txt");

while (input.good())
{
    input::getline(buffer, 1024);
    // ... do stuff...
}

input.close();
Run Code Online (Sandbox Code Playgroud)

为了便于说明,假设input.txt包含两条UTF-16 LE线,其长度小于200个wchar_t个字符.

在第一次调用getline之前,Visual Studio正确地识别该缓冲区是wchar_t的数组.您可以将鼠标悬停在调试器中的变量上,并看到该数组由16位值组成.但是,在调用getline返回之后,调试器现在显示缓冲区,就像是一个字节数组一样.

在第一次调用getline之后,缓冲区的内容是正确的(除了缓冲区被视为字节数组).如果input.txt的第一行包含UTF-16字符串L"123",则将其正确存储在缓冲区中(十六进制)"31 00 32 00 33 00"

我的第一个想法是reinterpret_cast<wchar_t *>(buffer)产生所需的结果(缓冲区现在被视为wchar_t数组)并且它包含我期望的值.

但是,在第二次调用getline之后(input.txt的第二行包含字符串L"456")缓冲区包含(hex)"00 34 00 35 00 36 00".请注意,这是不正确的(它应该是[hex] 34 00 35 00 36 00)

字节排序混乱的事实阻止我使用reinterpret_cast作为解决方案来解决这个问题.更重要的是,为什么std :: wifstream :: getline甚至将我的wchar_t缓冲区转换为char缓冲区呢?我的印象是,如果有人想使用字符,他们会使用ifstream,如果他们想使用wchar_t,他们会使用wifstream ...

我很难理解stl标题,但它几乎看起来好像wifstream是故意将我的wchar_t转换为char ...为什么?

我将不胜感激任何理解这些问题的见解和解释.

stl unicode-string visual-c++

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

将字符偏移转换为字节偏移(在Python中)

假设我有一堆UTF-8文件,我用unicode发送到外部API.API对每个unicode字符串进行操作,并返回带有(character_offset, substr)元组的列表.

我需要的输出是每个找到的子字符串的开始和结束字节偏移量.如果我很幸运,输入文本只包含ASCII字符(使字符偏移和字节偏移相同),但情况并非总是如此.如何找到已知开始字符偏移量和子字符串的开始和结束字节偏移量?

我自己已经回答了这个问题,但期待这个问题的其他解决方案更强大,更有效,和/或更具可读性.

python unicode-string offset bytestring

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

替换MS SQL Server中的特定Unicode字符

我正在使用MS SQL Server Express 2012.

我在网格结果中删除unicode字符U + 02CC(十进制:716)时遇到问题.原文是'λeˌβár'.

我试过这样,它不起作用:

SELECT ColumnTextWithUnicode, REPLACE(ColumnTextWithUnicode , '?','') 
FROM TableName
Run Code Online (Sandbox Code Playgroud)

该列具有Latin1_General_CI_AS排序规则,数据类型为nvarchar.我尝试将排序规则更改为二进制文件,但也没有成功:

SELECT ColumnTextWithUnicode, REPLACE(ColumnTextWithUnicode collate Latin1_General_BIN, '?' collate Latin1_General_BIN,'') 
FROM  TableName
Run Code Online (Sandbox Code Playgroud)

甚至使用NChar()函数,如:

SELECT ColumnTextWithUnicode, REPLACE(ColumnTextWithUnicode , NCHAR(716),'') 
FROM TableName
Run Code Online (Sandbox Code Playgroud)

所有三个结果都是'λeˌβár'.

但是,如果我将列转换为varchar,如:

SELECT ColumnTextWithUnicode, REPLACE(CAST(ColumnTextWithUnicode as varchar(100)), '?','') 
FROM TableName
Run Code Online (Sandbox Code Playgroud)

结果变为'eßár',删除第一个字符和'ˌ'.

任何想法只删除'ˌ'?

sql-server replace unicode-string

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

删除unicode [u']

我有这个字符串,从网页输入.

s = "[u'967208', u'411600', u'460273']"
Run Code Online (Sandbox Code Playgroud)

我想删除括号[ ]u'.

我也想制作new line breaks逗号而不是逗号,.

我花了很多时间寻找解决方案,包括编码和正则表达式,但我似乎无法让它工作.

更新:这是我用来检索字符串的内容:

import selenium
import re
input = webdriver.find_element_by_class_name("class_name")
s = re.findall("((?<=\()[0-9]*)", input.text)
Run Code Online (Sandbox Code Playgroud)

python unicode-string python-2.7

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

如何在 c++ Linux 中使用 ICU 库将 UnicodeString 转换为 windows-1251?

我有这段代码,它将 UTF-8 字符串转换为 Unicode:

#include <unicode/unistr.h>
//included other header files

int main(int argc, char** argv) {
    std::string s("some string");
        // convert std::string to ICU's UnicodeString
        UnicodeString ucs = UnicodeString::fromUTF8(StringPiece(s.c_str()));

        // convert UnicodeString to std::wstring
        std::wstring ws;
        for (int i = 0; i < ucs.length(); ++i)
            ws += static_cast<wchar_t>(ucs[i]);

        std::wcout << ws;
}
Run Code Online (Sandbox Code Playgroud)

我无法理解如何将此 UnicodeString 转换为 windows-1251 (cp1251)。我应该在 Linux 中使用哪个函数来执行此操作?

c++ unicode unicode-string icu

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

如何将字符串转换为 unicode?

我有我的一篇文字

\n\n
Japanese:  \xe3\x81\x93\xe3\x81\xaeOTP\xe3\x82\x92\xe4\xbd\xbf\xe7\x94\xa8\xe3\x81\x97\xe3\x81\xa6Quik\xe3\x83\x89\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\x96\xe3\x81\xab\xe3\x83\xad\xe3\x82\xb0\xe3\x82\xa4\xe3\x83\xb3\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82 \xe3\x81\x93\xe3\x81\xaeOTP\xe3\x82\x92\xe8\xaa\xb0\xe3\x81\xa8\xe3\x82\x82\xe5\x85\xb1\xe6\x9c\x89\xe3\x81\x97\xe3\x81\xaa\xe3\x81\x84\xe3\x81\xa7\xe3\x81\x8f\xe3\x81\xa0\xe3\x81\x95\xe3\x81\x84\n
Run Code Online (Sandbox Code Playgroud)\n\n

我有它的unicode转换

\n\n
Unicode:  3053306e004f0054005030924f7f752830573066005100750069006b30c930e930a430d6306b30ed30b030a430f33057307e3059300200203053306e004f0054005030928ab030683082517167093057306a30443067304f306030553044\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我用一些在线工具完成的。现在我需要使用nodejs做同样的事情。

\n\n

所以我的问题是 Unicode 类型是什么?如何将日语文本转换为 unicode?

\n

javascript unicode unicode-string node.js

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

如何反转“String.fromCodePoint”,即将字符串转换为代码点数组?

String.fromCodePoint(...[127482, 127480])给了我一面美国国旗 ()。

如何将标志变回[127482, 127480]

javascript string codepoint unicode-string

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

确定字符是字母还是数字

鉴于Go字符串是unicode,有没有办法安全地确定字符(例如字符串中的第一个字母)是字母还是数字?在过去,我只会检查ASCII字符范围,但我怀疑使用unicode字符串会非常可靠.

string unicode-string go

0
推荐指数
1
解决办法
117
查看次数

用python中的字符替换所有unicode代码

我有一个看起来像这样的文本文件:

  • l\u00f6yt\u00e4\u00e4

但所有 unicode 字符都需要用相应的字符替换,并且应该如下所示:

  • 罗伊泰

问题是我不想自己替换所有 unicode 代码,自动执行此操作的最有效方法是什么?我的代码现在看起来像这样,但它确实需要改进!(代码在 Python3 中)

import io
input = io.open("input.json", "r", encoding="utf-8")
output = io.open("output.txt", "w", encoding="utf-8")
with input, output:
    # Read input file.
    file = input.read()
    file = file.replace("\\u00e4", "ä")
    # I think last line is the same as line below:
    # file = file .replace("\\u00e4", u"\u00e4")
    file = file.replace("\\u00c4", "Ä")
    file = file.replace("\\u00f6", "ö")
    file = file.replace("\\u00d6", "Ö")
    .
    .
    . 
    # I cannot put all codes in unicode here manually!
    . …
Run Code Online (Sandbox Code Playgroud)

python unicode json unicode-string python-3.x

0
推荐指数
1
解决办法
3744
查看次数