尝试(仍然需要 2 天)弄清楚如何删除第一个数字,然后是 ";"
并保留其余数字,但仍然删除所有 ";"
并将它们替换为制表符 ("\t")
。
基数(由脚本从一个 .txt 文件加载):
1;999.99;999.99;-999.99 <-- should be 999.99 999.99 -999.99 --><br />
2;248.22;257.78;-10.58 <-- should be 248.22 257.78 -10.58 --><br />
3;235.54;149.58;-14.32 <-- should be 235.54 149.58 -14.32 --><br />
10;225.54;147.58;-14.32 <-- should be 225.54 147.58 -14.32 --><br />
列表上升到 99; 我试过了
replace(/.*;(?! \.d+;)/g, "\t");
但这将删除所有“;”和数字,最后一个数字除外。 我想不通。谁能帮忙?
我的完整代码尝试了 "hex494D49"
的答案:
function readTheNpFile01() { var initNpFile = new ActiveXObject("Scripting.FileSystemObject"); projektname = projektname_input.value; openNP01 = initNpFile.OpenTextFile("C://wamp/www/CM5_demo/cnc_temp/" + projektname + ".cnc.01np", 1, false); readALLofNP01 = openNP01.ReadAll().replace(/0;0.0;0.0;0.0/i, "");//.slice(7); for(i = 0; i < readALLofNP01.length; i++){ console.log(readALLofNP01[i].replace(/(^\d+;)|;/g, '\t')); } $('#NP01row').html(readALLofNP01); //put the numbers in my html ID openNP01.Close(); }
最佳答案
var n = "1;999.99;999.99;-999.99";
n = n.slice(n.indexOf(';')+1).replace(/;/g, "\t");
关于javascript - 删除第一个数字,然后是 ";",然后删除其余的 ";",但保留后面的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24677759/