[英]How to combine comma-separated string?
我的情况很简单:
我已经完成了上述3个步骤,但是有一个小问题。
如您所见,还原的内容以逗号分隔。
我只是想知道如何获取与原始文件相同的内容。
下面是我的代码:
testRestore() {
// test input : 2 split files and 1 parity file
this.file.readAsArrayBuffer(this.path, '0_test.txt').then(arraybuffer => {
var temp = [];
temp[0] = arraybuffer;
alert(this.ab2str(temp[0]));
this.file.readAsArrayBuffer(this.path, '1_test.txt').then(arraybuffer => {
temp[1] = arraybuffer;
alert(this.ab2str(temp[1]));
this.file.readAsArrayBuffer(this.path, '3_test.txt').then(arraybuffer => {
temp[2] = arraybuffer;
alert(this.ab2str(temp[2]));
this.file.writeFile(this.path, 'restored_file.txt', this.genParity(temp));
});
});
});
}
// Input : string object array
// Output : 1 parity buffer
genParity(temparr) {
alert('here, temparr = ' + temparr);
var parityBuf;
for (let k = 0; k < temparr.length - 1; k++) {
parityBuf = this.doParity(this.ab2str(temparr[k]), this.ab2str(temparr[k + 1]));
}
alert('parityBuf = ' + parityBuf);
return parityBuf;
}
doParity(str1, str2) {
//String to Array of char codes
let transform = (n) => n.split("").map(v => v.charCodeAt(0));
let a = transform(str1);
let b = transform(str2);
let asc = a.map((v, i) => String.fromCharCode(v ^ b[i]));
return asc;
}
任何意见,将不胜感激。 谢谢。
※这段代码是TypeScript,我使用了Ionic F / W( readAsArrayBuffer(path, name, contents)
)的本机插件,但是我敢肯定,如果您熟悉JavaScript,就不会有任何问题可以理解和修复。问题。
使用join
功能:
yourArray.join('');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.