so i need to edit VIN data in text file i have code to edit one data. but i need code to edit multiple VIN data in text file
i created VIN data and stored in VIN array now i want code to modify multiple vin’s
this how text file data looks and VIN is EB6A9EBHD96FA5MDH
L|10071887|1564|EB6A9EBHD96FA5MDH|Jeep|Wrangler JK|
L|10071887|1564|EB6A9EBHD96FA5MDH|Jeep|Wrangler JK|
L|10071887|1564|EB6A9EBHD96FA5MDH|Jeep|Wrangler JK|
below is the code can someone please help me with this? iam expecting modification in code to edit multiple vin data in text file
`return new Promise((resolve, reject) => {
let filePath = fileSourcePath+fileName;
const fs = require("fs");
var data = fs.readFileSync(filePath, "utf8");
function replaceRange(s, start, end, substitute) {
return s.substring(0, start) + substitute + s.substring(end);
}
console.log("before editing : ", data)
let field=[Vin];
let startPos=[716]
let endPos=[733]
let i;
let replaceValues;
console.log("lenght:",field.length)
for(i=0; i<field.length; i++) {
replaceValues=replaceRange(data,startPos[i],endPos[i],field[i]); // for .txt file
data = replaceValues
}
console.log(data);
fs.writeFile(filePath, data, (err) => {
if (err) console.log(err);
console.log("file edited Successfully!");
resolve();
});
});`
SHRINAND BITLA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.