File tree Expand file tree Collapse file tree 4 files changed +56
-11
lines changed Expand file tree Collapse file tree 4 files changed +56
-11
lines changed Original file line number Diff line number Diff line change @@ -47,5 +47,32 @@ public string LetterChanges(string str)
47
47
48
48
return result ;
49
49
}
50
+
51
+ // Have the function LetterCapitalize(str) take the str parameter being passed
52
+ // and capitalize the first letter of each word. Words will be separated by
53
+ // only one space.
54
+ public string LetterCapitalize ( string str )
55
+ {
56
+ string result = String . Empty ;
57
+ char [ ] chars = str . ToCharArray ( ) ;
58
+
59
+
60
+ for ( int index = 0 ; index < chars . Length ; index ++ )
61
+ {
62
+ if ( index == 0 && Char . IsLower ( str [ index ] ) )
63
+ {
64
+ chars [ index ] = Char . ToUpper ( chars [ index ] ) ;
65
+ }
66
+
67
+ if ( index > 0 && chars [ index - 1 ] == ' ' )
68
+ {
69
+ chars [ index ] = Char . ToUpper ( chars [ index ] ) ;
70
+ }
71
+ }
72
+
73
+ result = new string ( chars ) ;
74
+
75
+ return result ;
76
+ }
50
77
}
51
78
}
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ Check Numbers 02/10/2021 NumberCheck
8
8
Find Intersection 02/11/2021 StringIntersection
9
9
First Factorial 02/22/2021 Factorial
10
10
First Reverse 02/22/2021 StringReverse
11
- Letter Capitalize
11
+ Letter Capitalize 02/22/2021 ChangeLetter
12
12
Letter Changes 02/22/2021 ChangeLetter
13
13
Longest Word
14
14
Moving Median
Original file line number Diff line number Diff line change @@ -26,22 +26,23 @@ static void Main(string[] args)
26
26
tc . Test_FirstFactorial ( ) ;
27
27
tc . Test_FirstReverse ( ) ;
28
28
tc . Test_LetterChanges ( ) ;
29
+ tc . Test_LetterCapitalize ( ) ;
29
30
30
31
// Medium
31
32
Console . WriteLine ( "Medium Code Challenges:" ) ;
32
- tc . Test_Consecutive ( ) ;
33
- tc . Test_KUniqueCharacters ( ) ;
34
- tc . Test_NumberEncoding ( ) ;
35
- tc . Test_PrimeMover ( ) ;
36
- tc . Test_MinWindowSubstring ( ) ;
37
- tc . Test_RunLength ( ) ;
38
- tc . Test_StringReduction ( ) ;
39
- //tc.Test_TreeConstructor();
33
+ // tc.Test_Consecutive();
34
+ // tc.Test_KUniqueCharacters();
35
+ // tc.Test_NumberEncoding();
36
+ // tc.Test_PrimeMover();
37
+ // tc.Test_MinWindowSubstring();
38
+ // tc.Test_RunLength();
39
+ // tc.Test_StringReduction();
40
+ //// tc.Test_TreeConstructor();
40
41
41
42
// Hard
42
43
Console . WriteLine ( "Hard Code Challenges:" ) ;
43
- tc . Test_KaprekarsConstant ( ) ;
44
- tc . Test_Determinant ( ) ;
44
+ // tc.Test_KaprekarsConstant();
45
+ // tc.Test_Determinant();
45
46
}
46
47
}
47
48
}
Original file line number Diff line number Diff line change @@ -199,6 +199,23 @@ public void Test_LetterChanges()
199
199
Console . WriteLine ( "Output: {0}" , changer . LetterChanges ( str ) ) ;
200
200
Console . WriteLine ( ) ;
201
201
}
202
+ public void Test_LetterCapitalize ( )
203
+ {
204
+ ChangeLetter changer = new ChangeLetter ( ) ;
205
+
206
+ string str = "applez" ;
207
+
208
+ Console . WriteLine ( "Letter Capitalize:" ) ;
209
+ Console . WriteLine ( "Input: {0}" , str ) ;
210
+ Console . WriteLine ( "Output: {0}" , changer . LetterCapitalize ( str ) ) ;
211
+ Console . WriteLine ( ) ;
212
+
213
+ str = "coder byte" ;
214
+
215
+ Console . WriteLine ( "Input: {0}" , str ) ;
216
+ Console . WriteLine ( "Output: {0}" , changer . LetterCapitalize ( str ) ) ;
217
+ Console . WriteLine ( ) ;
218
+ }
202
219
#endregion
203
220
204
221
#region Medium Challenges
You can’t perform that action at this time.
0 commit comments