現在、スペースを削除してハイフンに置き換えるには、次の方法があります。スペースをハイフンに置き換え、ドットを何も置き換えずに同じ変数に保持するにはどうすればよいですか?
url = url.replace(/\s/g, '-');
現在、スペースを削除してハイフンに置き換えるには、次の方法があります。スペースをハイフンに置き換え、ドットを何も置き換えずに同じ変数に保持するにはどうすればよいですか?
url = url.replace(/\s/g, '-');
url = url.replace(/\s/g, '-').replace(/\./g, '');
するかもしれません。
私はこれを使用します:
// This little gadget does replace for all not just first occurence like the native javascript function.
String.prototype.replaceAll = function(strTarget, strSubString){
var strText = this;
var intIndexOfMatch = strText.indexOf(strTarget);
while (intIndexOfMatch != -1){
strText = strText.replace(strTarget, strSubString);
intIndexOfMatch = strText.indexOf(strTarget);
}
return(strText);
}