我的程序是逐行读取文本文件。我希望它将每行的数字拆分成单独的变量。例如:
这是从文本文件中的行读取的字符串:
constructor(elementRef:ElementRef, renderer:Renderer) {
renderer.listen(elementRef.nativeElement, 'click', (event) => {
console.log('clicked', event, elementRef.nativeElement);
this.sleep(5000)
});
}
// we can mock waiting for small period of time http://stackoverflow.com/questions/16873323/javascript-sleep-wait-before-continuing
private sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
我希望将逗号放入变量之前的每个值:
FTSE,D,20160104,6242.32,6242.32,6071.01,6093.43,0
伪代码:
A = 'FTSE'
B = 'D'
C = '20160104'
...
答案 0 :(得分:1)
for line in file:
A,B,C,D,E,F,G,H = line.split(',')
仅当您确定该行只包含8个部分时才有效。