标签: character-encoding

WebView中的Android汉字

我有一个 html 代码,我将其保存在home.txt文件中并将其放置在原始文件夹中。现在我想在一个WebView. 我使用了以下代码。

homeWebview = (WebView) findViewById(R.id.homeWebview);
InputStream fileStream = getResources().openRawResource(R.raw.home); 
int fileLen = fileStream.available();

// Read the entire resource into a local byte buffer. 
byte[] fileBuffer = new byte[fileLen]; 
fileStream.read(fileBuffer);

fileStream.close();  
displayText = new String(fileBuffer);

//Display content.          
homeWebview.loadData(displayText, "text/html", "utf-8");
Run Code Online (Sandbox Code Playgroud)

它工作正常。现在我必须在html中显示一些中文字符。我在home.txt中添加了汉字。这是html代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Language</title>
<style type="text/css">
body {font-family: HelveticaExt-normal, Helvetica, Arial, sans-serif;margin:0;font-size:20px;color:#000000;}
.mainWrapper {margin:0;}
p {margin: 10px;}
p.bodytext {margin: 0 10px 20px;}
.headerText { background:#eeeeee; background: -webkit-gradient(linear, …
Run Code Online (Sandbox Code Playgroud)

android character-encoding cjk webview

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

以非英文特殊字符为框的经典 ASP

我目前正在为我的一个项目开发经典 ASP。对于非英语语言,我得到的是盒子而不是特殊字符。我正在使用 UTF-8 进行渲染,但有时字符会进入框。有时候点击刷新就恢复正常了。

我按照下面的所有步骤,但我仍然遇到这个问题

  1. XML:

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

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    
    Run Code Online (Sandbox Code Playgroud)
  3. content-type: text/html; charset=utf-8

我在这里错过了什么吗?谢谢。

character-encoding asp-classic

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

改变 MySQL 列编码,级联到 FK

我有一张名为provider. 在provider表中,我有一列名为provider. 该列的字符编码目前为latin1:

`provider` varchar(60) CHARACTER SET latin1 NOT NULL DEFAULT '',
Run Code Online (Sandbox Code Playgroud)

其他几个表FKprovider.provider也参考。我将如何更改编码utf8并将所有更改级联到外键引用?相当于:

ALTER TABLE provider MODIFY
    provider VARCHAR (60)
    CHARACTER SET utf8
    COLLATE utf8_unicode_ci;
Run Code Online (Sandbox Code Playgroud)

但是对于 FK 也引用它的所有列。(注意:根据自己的错误执行上述操作。)

mysql sql utf-8 character-encoding

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

Unicode 字符 Visual C++

我试图让我的程序使用 unicode 字符。我在 Windows 7 x32 机器上使用 Visual Studio 2010。

我想打印的是皇后符号(“\ ul2655”),但它不起作用。我已将我的解决方案设置为使用 unicode。

这是我的示例代码:

 #include <iostream>
 using namespace std;

 int main()
 {
    SetConsoleOutputCP(CP_UTF8);
    wcout << L"\u2655";

    return 0;
 }
Run Code Online (Sandbox Code Playgroud)

此外,我尝试了许多其他建议,但没有任何效果。(例如,更改cmd字体,应用chcp 65001,与SetConsoleOutputCP(CP_UTF8)等相同)。

问题是什么?我还是第一次遇到这样的情况。在 linux 上,它是不同的。

谢谢你。

c++ unicode utf-8 character-encoding visual-studio-2010

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

将文件从 ISO 8859-6 转换为 UTF-8 后无法看到阿拉伯字符

在我的应用程序中,我正在读取一个包含一些阿拉伯字符(编码为ISO 8859-6)的文件,我正在将其转换为UTF-8编码并使用BufferedWriter. 但是,在我新生成的文件中,我看不到阿拉伯字符,而是出现了几个问号。

来自我的原始文件的片段

Sample Data//????
Another line,
One more line/????
Run Code Online (Sandbox Code Playgroud)

来自生成文件的片段

 Sample Data//????
 Another line,
 One more line/????
Run Code Online (Sandbox Code Playgroud)

我正在使用以下方法进行转换:

private String convertCharSet(String data, String sourceCharacterCode, String destinationCharacterCode) throws UnsupportedEncodingException
{
        Charset charsetSource = Charset.forName(sourceCharacterCode);
        Charset charsetDestination = Charset.forName(destinationCharacterCode);
        ByteBuffer inputByteBuffer = ByteBuffer.wrap(data.getBytes(sourceCharacterCode));
        CharBuffer charBuffer = charsetSource.decode(inputByteBuffer);
        ByteBuffer outputByteBuffer = charsetDestination.encode(charBuffer);
        return new String(outputByteBuffer.array(), destinationCharacterCode);
}
Run Code Online (Sandbox Code Playgroud)

我正在使用以下方法写入文件

public static void writeToFile(String filePath, String data) throws IOException
{
    BufferedWriter out = null;
    try
    {
        out …
Run Code Online (Sandbox Code Playgroud)

java utf-8 character-encoding

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

为什么 Encoding.default_external 不尊重 LANG?

我的理解是,Ruby 的Encoding.default_external默认值基于环境变量LC_ALLLANG,优先于前者。我遇到了几个错误,即使环境变量设置为 UTF-8,默认外部编码也会以某种方式最终设置为 ASCII。

例如:

$ irb
irb(main):001:0> Encoding.default_external
=> #<Encoding:US-ASCII>
irb(main):002:0> ENV['LC_ALL']
=> nil
irb(main):003:0> ENV['LANG']
=> "en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)

在发生这种情况的环境中,我还搜索了所有为手动设置默认外部编码的代码加载的 gem,但没有找到任何东西。我在上面看到的怎么可能?我在上面使用 Ruby 2.2,但我已经看到这种情况发生在所有 Ruby 2.x 版本上。

ruby ascii utf-8 character-encoding

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

NSRegularExpression 中的 Unicode 字符 (UTF-32) 字符串编码

我正在为 Swift 中的 Turtle 格式的 RDF 数据编写解析器。海龟语法将模式定义PN_CHARS_BASE

[163s]  PN_CHARS_BASE ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
Run Code Online (Sandbox Code Playgroud)

(请参阅W3C Turtle 推荐)。

模式中的最后一组[#x10000-#xEFFFF]超出了 UTF-16 字符串编码的范围。这里需要UTF-32。

这种模式用于匹配,例如,在前缀的第一个字符的字符串前缀,如foaffoaf:name,数这里不允许。

我想NSRegularExpression用于解析海龟文件。所以为了匹配PN_CHARS_BASE模式,我有以下测试代码:

    let PN_CHARS_BASE = "[A-Z]|[a-z]|[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u10000-\\uEFFFF]"
    do {
        let teststr = "9"
        let regex = try NSRegularExpression(pattern: PN_CHARS_BASE, options: [])
        let matches = …
Run Code Online (Sandbox Code Playgroud)

regex character-encoding nsregularexpression swift turtle-rdf

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

当字节对象显然只包含字符时,将 Python 3 字节对象转换为字符串

我是 Python 3 的新手,似乎我不能完全掌握 unicode 和字符编码。

我正在使用另一个工具的输出,该工具将 html 页面的内容作为字节对象返回。我们使用的其他工具需要此输出为字节类型,但是,我想将字节输出转换为字符串以进行一些解析和与其他字符串的比较。对于我感兴趣的情况,打印输出字节对象只显示字符而不显示 \x 或 \u 二进制文件。我对如何最好地做到这一点以及为什么创建所需输出的方法实际上起作用感到有些困惑。

我在其他地方读到 .decode() 应该在这种情况下使用,这确实有效,但我不明白为什么我要解码一个已经是字符的对象。据我了解,解码用于二进制数,例如:

>>> b'\x41'.decode('utf-8')
'A'
Run Code Online (Sandbox Code Playgroud)

在我的理解中,我真正想要做的就是告诉 Python 一个被标记为字节类型对象的对象实际上是一个 str 对象。简单地在 bytes 对象上使用 str() 函数也可以实现这个目标,但要添加“b”前缀并在字符串周围添加引号。

这是我正在使用的两个解决方案:

>>> str(b'htmltext')
"b'htmltext'"

>>> b'htmltext'.decode('utf-8')
'htmltext'
Run Code Online (Sandbox Code Playgroud)

从本质上讲,这些解决方案中的任何一个似乎都能实现我正在寻找的东西,但 decode() 显然看起来更干净,而且从我读过的内容来看,这是推荐的方法。我想知道为什么 decode() 有效,因为显然我没有将二进制数转换为字符。此外,除了输出中不吸引人的“b”和引号之外,还有其他任何原因表明 str() 在这里不是有效的解决方案吗?

python string character-encoding python-3.x

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

将 ByteArray 转换为字符串并返回会产生不同的字符串

我必须存储巨大的布尔值列表,我选择将它们存储为字节数组作为字符串。但我不明白,为什么转换为字符串并返回会产生不同的字符串值:

支持方式:

  fun ByteArray.string(): String {

    var str = ""

    this.reversed().forEach {
      str += intToString(it, 4)
    }

    return str
  }

  fun intToString(number: Byte, groupSize: Int): String {
    val result = StringBuilder()

    for (i in 7 downTo 0) {
      val mask = 1 shl i
      result.append(if (number.toInt() and mask != 0) "1" else "0")

      if (i % groupSize == 0)
        result.append(" ")
    }
    result.replace(result.length - 1, result.length, "")

    return result.toString()
  }
Run Code Online (Sandbox Code Playgroud)

第一个例子:

给定选定的索引 [0, 14],我的代码转换为:作为字节:[1, 64]。.string()产生:

0100 0000 0000 …

java byte utf-8 character-encoding kotlin

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

读取文本文件返回 UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in Python

即使我提到过,我也在使用 Python3 读取文本文件,encoding但它重新运行:

UnicodeDecodeError:'utf-8' 编解码器无法解码位置 96 中的字节 0x92:无效起始字节 [05/May/2018 03:35:45]“POST /app/HTTP/1.1”500 14383

它不是重复的,但它特定于byte 0x92.

这是我尝试过的:

txt = Path(text_path).read_text(encoding="utf-8")
Run Code Online (Sandbox Code Playgroud)

python character-encoding

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