I have a string with tab-separated data copied from Excel.(我有一个字符串,其中包含从Excel复制的制表符分隔的数据。)
The javascript split does not recognise the 2nd tab in the string.(javascript拆分无法识别字符串中的第二个标签。) I have pasted the string into notepad++ to see the tabs and they are all there.(我已将字符串粘贴到notepad ++中,以查看选项卡,它们都在那里。) Exploding the string in PHP works fine.(在PHP中爆炸字符串可以正常工作。) The test code is:(测试代码为:)
function testTab(str) {
var strSplit = str.split('');
for (i=0; i < strSplit.length; i++){
console.log('strSplit['+i+'] = '+strSplit[i]);
}
}
The console output (where the tab between 1st and 2nd item is not recognised):(控制台输出(其中无法识别第一项和第二项之间的选项卡):)
strSplit[0] = 0.02194 0.028940568
strSplit[1] = 0.05227
strSplit[2] = 0.040229885
strSplit[3] = 0.04650
strSplit[4] = 0.035630689
strSplit[5] = 0.07055
strSplit[6] = 0.015557256
strSplit[7] = 0.01960
strSplit[8] = 0.03527
strSplit[9] = 0.05276
strSplit[10] = 0.05669
strSplit[11] = 0.05680
strSplit[12] = 0.04464
strSplit[13] = 1
Unsure if the string copies correctly with all tabs, but here it is:(不确定该字符串是否正确复制了所有选项卡,但是这里是:)
const str = `0.02194 0.028940568 0.05227 0.040229885 0.04650 0.035630689 0.07055 0.015557256 0.01960 0.03527 0.05276 0.05669 0.05680 0.04464 1`; function testTab(str) { var strSplit = str.split('\t'); for (i = 0; i < strSplit.length; i++) { console.log('strSplit[' + i + '] = ' + strSplit[i]); } } testTab(str)
ask by Svea translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…