最后出现点(。)后,我可以删除或替换任何文本吗?
ex)OUTsoundfile.123054236.123054236.wav
我想删除 .wav 或用空字符串替换 .wav
无法使用subString
,因为输入文本中可能不存在 .wav。
最后出现点(。)后,我可以删除或替换任何文本吗?
ex)OUTsoundfile.123054236.123054236.wav
我想删除 .wav 或用空字符串替换 .wav
无法使用subString
,因为输入文本中可能不存在 .wav。
这将是正确的正则表达式:
var myString = "ex)OUTsoundfile.123054236.123054236.wav";
var output = myString.replace(/\.[^.]*$/, '');
尝试
var trimwav = "ex)OUTsoundfile.123054236.123054236.wav";
alert(trimwav.substr(0,x.lastIndexOf(".")));
使用普通的旧 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(".");