<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
<script language = "VBScript">
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
Sub Window_onLoad
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("fr.yml", 1)
row = 0
Do Until file.AtEndOfStream
'Msgbox(file.Readline)
line = file.Readline
dict.Add row, line
row = row + 1
Loop
nnn.innerHTML = dict(15)
hhh.innerHTML = "prêt àprêt à"
End Sub
</script>
<body>
<p id="nnn">éprêt à</p>
<p id="hhh">éprêt à</p>
</body>
在此代码中,<p id="nnn">
会显示Terminé
,<p id="hhh">
会显示prêt àprêt à
。{/ p>
我的fr.yml文件有第16行Terminé
。
答案 0 :(得分:4)
您的输入文件(fr.yml
)似乎是UTF-8编码的。 FileSystemObject
方法无法处理该编码,因此您需要使用ADODB.Stream
,如@ Ekkehard.Horner所建议:
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 'text
stream.Charset = "utf-8"
stream.LoadFromFile "fr.yml"
For Each line In Split(stream.ReadText, vbNewLine)
dict.Add row, line
row = row + 1
Next
stream.Close
答案 1 :(得分:1)
我通过向OpenTextFile()
添加一个参数来解决这个问题。
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
Sub Window_onLoad
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("fr.yml", 1, -1)
row = 0
Do Until file.AtEndOfStream
'Msgbox(file.Readline)
line = file.Readline
dict.Add row, line
row = row + 1
Loop
nnn.innerHTML = dict(15)
hhh.innerHTML = "prêt àprêt à"
End Sub
参考Here