我可以在最后使用点(。)
后删除或替换任何文本ex)OUTsoundfile.123054236.123054236.wav
我想删除.wav或用空字符串替换.wav
无法使用subString
,因为.wav可能不存在于输入文本中。
答案 0 :(得分:4)
答案 1 :(得分:1)
这将是正确的正则表达式:
var myString = "ex)OUTsoundfile.123054236.123054236.wav";
var output = myString.replace(/\.[^.]*$/, '');
答案 2 :(得分:1)
答案 3 :(得分:0)
使用普通的旧JavaScript:
var filename = "OUTsoundfile.123054236.123054236.wav";
var pieces = filename.split(".");
// pieces is an array that looks like this:
// ["OUTsoundfile", "123054236", "123054236", "wav"]
// Remove the last element from pieces, i.e. "wav"
// If you want to do anything with this last piece, such as check what the
// piece you removed was, use the return value of this statement.
pieces.pop();
// pieces now just looks like this:
// ["OUTsoundfile", "123054236", "123054236"]
// Put the string back together
var newFilename = pieces.join(".");
// newFilename is now this string: "OUTsoundfile.123054236.123054236"
或者,没有评论:
var filename = "OUTsoundfile.123054236.123054236.wav";
var pieces = filename.split(".");
pieces.pop();
var newFilename = pieces.join(".");
答案 4 :(得分:0)
尝试
var trimwav = "ex)OUTsoundfile.123054236.123054236.wav";
alert(trimwav.substr(0,x.lastIndexOf(".")));