Find the Capitalsdescription:instructions
Write a function, takes a single string ( word
) as argument. The function must return an ordered list containing the indexes of any capital letters in the string.
Example
Assert.AreEqual(Kata.Capitals("CodEWaRs"), new int[]{0,3,4,6});
usingSystem;usingSystem.Linq; Public Static classkata{ Public Static int[] Capitals (stringword) { //Write Your code here int[] Array =New int[] { }; if(Word = =NULL|| Word = =string. Empty) {returnArray; } stringTMP =Word. ToLower (); returnEnumerable.range (0Tmp. Length). Where (i = word[i]! =Tmp[i]). ToArray (); }}
Other people's Solution:
It is worth learning that the char itself has a function that determines whether the uppercase
usingSystem.Collections.Generic;usingSystem; Public Static classkata{ Public Static int[] Capitals (stringword) { varCapitalindexes =Newlist<int>(); for(vari =0; I < Word. Length; i++) { if(Char. Isupper (Word[i]) capitalindexes.add (i); } returnCapitalindexes.toarray (); }}
Find the Capitals