0

我在 .js 文件中有一个数组,但我希望能够通过单行(无逗号)在 .txt 文件中创建我的数组。所以一个数组看起来像:

pickWords =
[
  "Hi!",
  "Welcome!",
  "Hello!"
]

但相反,我想从 .txt 文件中提取数组......到目前为止,这是我的代码:

FileName = "/array1.txt"

'Open the file for input.
Set MyFile = fso.OpenTextFile(FileName, ForReading)

'Read from the file and display the results.

Do While MyFile.AtEndOfStream <> True
    TextLine = MyFile.ReadLine
    Document.Write TextLine & "<br />"
Loop
MyFile.Close

我想我正在寻找有关此主题的输入,因为当您在搜索中使用“文本”一词时,很难搜索网络。

嗯,抱歉,如果它不是 javascript,我将它从一个说它是 .. 在标签 JScript 下的网站拉出来。但也许 Jscript 不是 javascript。http://msdn.microsoft.com/en-us/library/h7se9d4f%28v=vs.85%29.aspx#Y342

好的,那么问题将是 ajax vs php 来拉取外部数组?

4

2 回答 2

1

这是 .net 框架的 javascript 吗?我知道这在使用 readLine 读取本地磁盘文件的浏览器情况下不起作用。

以下是使用 string.split() 函数将文件作为可用数组获取的方法:

FileName = "/array1.txt"
'Open the file for input.
Set MyFile = fso.OpenTextFile(FileName, ForReading)

fileString = "";
fileArray;

'Read from the file and display the results.
Do While MyFile.AtEndOfStream <> True
    fileString += MyFile.ReadLine
Loop
MyFile.Close

//Now you can use fileArray as an array 
//You might need to use "\r\n" instead of "\n"
fileArray = string.split("\n"); 
于 2011-07-19T19:03:46.317 回答
0

就像每个人都说这似乎不是一个javascript问题,但是:

当您搜索 google 并且您的关键词之一是常用词时,您需要查看可能的其他关键词。对你来说 fso 是一个很好的选择:

http://www.google.com/search?rlz=1C1CHKZ_enUS437US437&sourceid=chrome&ie=UTF-8&q=array+fso+read+from+file&qscrl=1

我得到了这个看起来像你需要的命中:

http://www.4guysfromrolla.com/webtech/tips/t101700-1.shtml

于 2011-07-19T19:09:09.550 回答