2010-03-03 20 views

回答

1

用正則表達式

"b sampletext3".replace(/^b/gm,function(x){return x.toUpperCase()}) 
B sampletext3 

並將其分配給String對象

String.prototype.toTitleCaseB=function(){ 
    return this.replace(/^b/gm,function(x){return x.toUpperCase()}) 
} 

以後會使用像

"b sampletext3".toTitleCaseB() 
B sampletext3 
+0

我認爲馬克是找'/^B。* $/mg'。無論如何,你打了很多... – Kobi 2010-03-03 11:29:07

+0

是的,有想法。非常感謝! – Mark 2010-03-03 11:31:44

+0

是的,我忽略了問題的一些部分,修正了。 – YOU 2010-03-03 11:32:06

2
  1. split串上\n
  2. 在結果數組上循環
  3. 使用substring提取第一個字母並對其進行測試
  4. 可選地將數組項設置爲自身。 toUpperCase()
  5. join陣列
相關問題