Ho bisogno di leggere un file e sostituire alcuni testi in quel file con contenuto dinamico.quando ho provato string.replace non funziona per i dati che ho letto dal file .Ma per la stringa funziona. Sto usando node.js ed express.string.replace non funziona nel server express node.js
fs.readFile('test.html', function read(err, data) {
if (err) {
console.log(err);
}
else {
var msg = data.toString();
msg.replace("%name%", "myname");
msg.replace(/%email%/gi, '[email protected]');
temp = "Hello %NAME%, would you like some %DRINK%?";
temp = temp.replace(/%NAME%/gi,"Myname");
temp = temp.replace("%DRINK%","tea");
console.log("temp: "+temp);
console.log("msg: "+msg);
}
});
uscita:
temp: Hello Myname, would you like some tea?
msg: Hello %NAME%, would you like some %DRINK%?
Grazie a tutti ... mi sono it..I Sono nuovo di javascript .. – Damodaran