当前位置: 动力学知识库 > 问答 > 编程问答 >

programming languages - How do I change file extension with javascript

问题描述:

Does anyone know an easy way to change a file extension in Javascript?

For example, I have a variable with "first.docx" but I need to change it to "first.html".

网友答案:

This will change the string containing the file name;

file = file.substr(0, file.lastIndexOf(".")) + ".htm";
网友答案:
file = file.replace(/\.[^\.]+$/, '.html');
网友答案:
var file = "first.docx";
file = file.split(".");
file = file[0]+".html";
分享给朋友:
您可能感兴趣的文章:
随机阅读: