0
我有以下字符串:如何使所有大寫在JavaScript除非字符串包含'
A new way's to get home
輸出需要是:
A New Way's To Get Home
我嘗試使用此代碼:
var string = "A new way's to get home";
string = string.replace(/\(\d+\)/g, '').trim().replace(': ', ' - ').replace(/\b[a-z]/g,function(f){return f.toUpperCase();});
alert(string);
但是我得到這個:
A New Way'S To Get Home
我需要得到所有字符串在開始到大寫,但在這裏問題是方式的,因爲它包含'和上面這個正則表達式需要返回'不是'我如何我需要重寫這個正則表達式來返回正確的值?
的[字符串轉換爲標題情況下使用JavaScript]可能的複製(https://stackoverflow.com/questions/196972/convert-string -to-title-case-with-javascript) – Daniel