请告诉我这是可能的。我有一个.txt文件,其数据排列像一个电子表格(我会使用excel而不是我没有它并且我已经破了)并且想从中拉出并指定为变量。 防爆。 (bla.txt) 第一行是标题 其次是数据 A | B | C 1 | 2 | 3 希望将它们分配为
Var x= A1
Var y= B2
Var z= C3
任何帮助都将不胜感激。
聚苯乙烯。所有这些都处于闭路状态,因此没有安全问题。
答案 0 :(得分:0)
It would be helpful if you could post your .txt file.
Also if you would like to use excel but cant afford it you should try LibreOffice or OpenOffice. They are both free and (at least LibreOffice is) FOSS.
To load this file into your javascript you can use Jquery to load it like this:
$.get('/path/to/data.txt', function(data) { //Gets file 'data.txt' and stores it in variable 'data'
//Code to execute after loading file
/*I’m not sure exactly how your .txt file is formatted so I don't know
How you want it stored into separate variables.
But you can do that here*/
});
Hopefully this at least helps you get started.
答案 1 :(得分:0)
This simple code might help for extracting the data from individual lines.
Note: But this will work when you have one character only between |
example
A|B|C 1|2|3
but will not work for
AA|BC|CS 11|2|3
Here it is
var line = "A|B|C 1|2|3";
var x = line.charAt(0) + line.charAt(6);
var y = line.charAt(2) + line.charAt(8);
var z = line.charAt(4) + line.charAt(10);
Use other string functions to get your job done for the second case i pointed out.
Refer to this w3schools page for more help http://www.w3schools.com/js/js_string_methods.asp