问题描述
我在Qt Creator中构建了一个GUI,我想阅读CSV。 到目前为止,我可以将CSV读取为HTTP请求,并可以通过以下功能将其显示为文本:
//read CSV Datei
function readTextFile(filename){
var xhr = new XMLHttpRequest;
xhr.open("GET",filename); // set Method and File
xhr.onreadystatechange = function() {
if(xhr.readyState === XMLHttpRequest.DONE){ // if request_status == DONE
var response = xhr.responseText;
screen.liste = response
console.log(response);
}
}
xhr.send(); // begin the request
}
在下面,我试图找到“数组”的各个条目。 有没有办法将此列表拆分为单个字符串? 列表有50行18列,其中的行用';'
分隔。例如,这是前两行:
P22;P64;P99;P20;P88;P18;50;90;80;90;40;0;10;0;40;80;60;20
P51;P44;P57;P46;P96;P10;20;40;50;80;20;60;50;80;0;30;10;50
...
解决方法
欢迎您! String QML类型扩展了JS String对象(请参见https://doc.qt.io/qt-5/qml-qtqml-string.html#details),因此您可以使用split()方法来获取数组中所需的标记,该标记可以用[]进行索引。>