我有这个文本文件:
/etc/openvpn/example.sh.passwd
userone:securepassworduserone
usertwo:securepasswordusertwo
我想从以下行中获取数据:
"u901_humext ""2019-02-10 00:00"" 99.97 99.97 99.97"
我的函数带有此类,但只能显示所有数据:
"u901_radpar ""2019-02-10 15:40"" 1002.9 1068.4 1034.3943396226"
和类似html的
name = u901_humext date = 2019-02-10 00:00 min = 99.97 avg = 99.97 max = 99.97
答案 0 :(得分:0)
将ArrayBuffer转换为字符串,然后尝试按以下行将文本拆分:
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}
const text = ab2str(reader.result);
const lines = text.split(/\r?\n/);
然后,您可以用空格将每一行分开以读取每个单独的值:
lines.forEach(line => {
const vars = line.split(' ');
console.log(vars);
});