简体   繁体   English

vbscript filesystemobject 如何编码字符?

[英]How does vbscript filesystemobject encode characters?

I have this vbscript code:我有这个 vbscript 代码:

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile("tmp.txt", 2, True)

    for i = 128 to 255
        s = chr(i)
        if lenb(s) <>2 then
            wscript.echo i
            wscript.quit
        end if
        ts.write s
    next
    ts.close

On my system, each integer is converted to a double byte character: there are no numbers in that range that cannot be represented by a character, and no number requires more than 2 bytes.在我的系统上,每个整数都转换为双字节字符:该范围内没有不能用字符表示的数字,也没有数字需要超过 2 个字节。 But when I look at the file, I find only 127 bytes.但是当我查看文件时,我发现只有 127 个字节。

This answer: https://stackoverflow.com/a/31436726/1335492 suggests the the FSO creates UTF files and inserts a BOM.这个答案: https : //stackoverflow.com/a/31436726/1335492建议 FSO 创建 UTF 文件并插入 BOM。 But the file contains only 127 bytes, and no Byte Order Mark.但该文件仅包含 127 个字节,并且没有 Byte Order Mark。

How does FSO decide how to encode text? FSO 如何决定如何编码文本? What encoding allows 8 bit single-byte characters?什么编码允许 8 位单字节字符? What encodings do not include 255 8 bit single-byte characters?哪些编码包含 255 个 8 位单字节字符?

(Answers about how FSO reads characters may also be interesting, but that's not what I'm specifically asking here) (关于 FSO 如何读取字符的答案也可能很有趣,但这不是我在这里特别要问的)

Edit: I've limited my question to the high-bit characters, to make it clear what the question is.编辑:我已经将我的问题限制在高位字符上,以明确问题是什么。 (Answers about the low-bit characters may also be interesting, but that's not what I'm specifically asking here) (关于低位字符的答案也可能很有趣,但这不是我在这里特别要问的)

I have this vbscript code:我有这个 vbscript 代码:

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile("tmp.txt", 2, True)

    for i = 128 to 255
        s = chr(i)
        if lenb(s) <>2 then
            wscript.echo i
            wscript.quit
        end if
        ts.write s
    next
    ts.close

On my system, each integer is converted to a double byte character: there are no numbers in that range that cannot be represented by a character, and no number requires more than 2 bytes.在我的系统上,每个整数都转换为双字节字符:该范围内没有不能用字符表示的数字,也没有数字需要超过 2 个字节。 But when I look at the file, I find only 127 bytes.但是当我查看文件时,我发现只有 127 个字节。

This answer: https://stackoverflow.com/a/31436726/1335492 suggests the the FSO creates UTF files and inserts a BOM.这个答案: https : //stackoverflow.com/a/31436726/1335492建议FSO创建UTF文件并插入BOM。 But the file contains only 127 bytes, and no Byte Order Mark.但是该文件仅包含127个字节,没有字节顺序标记。

How does FSO decide how to encode text? FSO 如何决定如何编码文本? What encoding allows 8 bit single-byte characters?什么编码允许 8 位单字节字符? What encodings do not include 255 8 bit single-byte characters?哪些编码包含 255 个 8 位单字节字符?

(Answers about how FSO reads characters may also be interesting, but that's not what I'm specifically asking here) (关于 FSO 如何读取字符的答案也可能很有趣,但这不是我在这里特别要问的)

Edit: I've limited my question to the high-bit characters, to make it clear what the question is.编辑:我将我的问题限制在高位字符上,以明确问题是什么。 (Answers about the low-bit characters may also be interesting, but that's not what I'm specifically asking here) (有关低位字符的答案也可能很有趣,但这不是我在这里特别要问的)

I have this vbscript code:我有这个 vbscript 代码:

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile("tmp.txt", 2, True)

    for i = 128 to 255
        s = chr(i)
        if lenb(s) <>2 then
            wscript.echo i
            wscript.quit
        end if
        ts.write s
    next
    ts.close

On my system, each integer is converted to a double byte character: there are no numbers in that range that cannot be represented by a character, and no number requires more than 2 bytes.在我的系统上,每个整数都转换为双字节字符:该范围内没有不能用字符表示的数字,也没有数字需要超过 2 个字节。 But when I look at the file, I find only 127 bytes.但是当我查看文件时,我发现只有 127 个字节。

This answer: https://stackoverflow.com/a/31436726/1335492 suggests the the FSO creates UTF files and inserts a BOM.这个答案: https : //stackoverflow.com/a/31436726/1335492建议FSO创建UTF文件并插入BOM。 But the file contains only 127 bytes, and no Byte Order Mark.但是该文件仅包含127个字节,没有字节顺序标记。

How does FSO decide how to encode text? FSO 如何决定如何编码文本? What encoding allows 8 bit single-byte characters?什么编码允许 8 位单字节字符? What encodings do not include 255 8 bit single-byte characters?哪些编码包含 255 个 8 位单字节字符?

(Answers about how FSO reads characters may also be interesting, but that's not what I'm specifically asking here) (关于 FSO 如何读取字符的答案也可能很有趣,但这不是我在这里特别要问的)

Edit: I've limited my question to the high-bit characters, to make it clear what the question is.编辑:我将我的问题限制在高位字符上,以明确问题是什么。 (Answers about the low-bit characters may also be interesting, but that's not what I'm specifically asking here) (有关低位字符的答案也可能很有趣,但这不是我在这里特别要问的)

ReadLine() 不工作 fpr Unicode,他读取所有文件 :(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM