相关疑难解决方法(0)

什么是ANSI格式?

什么是ANSI编码格式?它是系统默认格式吗?它与ASCII有什么不同?

ascii ansi character-encoding codepages

204
推荐指数
7
解决办法
31万
查看次数

将 Javascript BLOB 编码更改为 ANSI 而不是 UTF-8

我想知道是否可以使用 Javascript 和 ANSI 编码的 BLOB 保存一个简单的 txt 文件。

\n\n

目前,我有一个脚本创建一个带有 CRLF 行结尾但采用 UTF-8 编码的 txt 文件。

\n\n

可以用ANSI编码保存吗?我需要这个来导入需要 ANSI 而不是 UTF-8 的“旧”Windows 程序上的 txt 文件。

\n\n

这是我使用的示例:\n https://jsfiddle.net/UselessCode/qm5AG/

\n\n
let textFile = null;\n\nfunction makeTextFile () {\n    let text = `Some text with nice line endings\\nand special characters like \xc3\xa9 and \xc3\xbc.`;\n\n    const data = new Blob([text], {\n        type: "text/plain",\n        endings: "native"\n    });\n\n    if (textFile !== null) {\n        window.URL.revokeObjectURL(textFile);\n    }\n\n    textFile = window.URL.createObjectURL(data);\n\n    return textFile;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

javascript encoding blob ansi utf-8

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