我在javascript中遇到數組問題。我有這樣的數組:當字符爲大寫字符時的子串數組元素
Subjects[]:
[0] = 'Introduction to interesting things'
[1] = 'Cats and dogs'
[2] = 'I can't believe it's not butter Á machine lord'
[3] = 'I Intergalactic proton powered advertising droids '
正如你所看到的,在科目[2],有2串
'I can't believe it's not butter' and 'Á machine lord'
此外,在主題[3],將字符串 'I' 開始,這應該是
'Á machine lord I'.
有沒有辦法削減大寫的字符串開始並創建一個新的索引的字符串?像這樣:
Subjects[]:
[0] = 'Introduction to interesting things'
[1] = 'Cats and dogs'
[2] = 'I can't believe it's not butter'
[3] = 'Á machine lord I'
[4] = 'Intergalactic proton powered advertising droids'
我試過用.split
沒有成功。任何幫助將是有用的。
最簡單的方法:經過串。檢查當前單詞是否有大寫起始符號。檢查下一個單詞是否有大寫起始符號。如果你回答第一個問題是肯定的,第二個問題回答是否定的,分裂。在字符串的末尾重複,直到字符串爲空。 – Zeta