小编Ron*_*ink的帖子

将 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万
查看次数

在 React 中使用 useState 更新 2D 数组矩阵

我有以下功能:

import React, { useState } from "react";

const Sheet = () => {
  const [matrix, setMatrix] = useState([
    [null, null, null],
    [null, null, null],
    [null, null, null]
  ]);

  const handleChange = (row, column, event) => {
    let copy = [...matrix];
    copy[row][column] = +event.target.value;
    setMatrix(copy);

    console.log(matrix);
  };

  return (
    <div className="sheet">
      <table>
        <tbody>
          {matrix.map((row, rowIndex) => (
            <tr key={rowIndex}>
              {row.map((column, columnIndex) => (
                <td key={columnIndex}>
                  <input
                    type="number"
                    onChange={e => handleChange(rowIndex, columnIndex, e)}
                  />
                </td>
              ))}
            </tr>
          ))}
        </tbody>
      </table>
    </div> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

标签 统计

javascript ×2

ansi ×1

blob ×1

encoding ×1

reactjs ×1

utf-8 ×1