Last active
February 10, 2020 22:36
-
-
Save harrisonmalone/15174cea4019293b705d342cfc66779f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Text; | |
| namespace string_stuff | |
| { | |
| class StringChallenge { | |
| // Using a Console.WriteLine, display the number of letters in the startingMessage. | |
| // Using a Console.WriteLine, display the position or index of the "#" in the startingMessage. | |
| // Create a new string that contains the phrase "harrypotter". | |
| // Insert a space between the word "harry" and the word "potter". | |
| // Capitalize the word "harry" so that it reads as "Harry". | |
| // Find out the number of the amount of letters in the string you've got so far. | |
| public static void Solution() { | |
| string startingMessage = "C# is actually two C++ in a trenchcoat!"; | |
| Console.WriteLine(startingMessage.Length); | |
| int index = startingMessage.IndexOf("#"); | |
| // 1 | |
| Console.WriteLine(index); | |
| string name = "harrypotter"; | |
| name = name.Insert(5, " "); | |
| // 2 | |
| Console.WriteLine(name); | |
| name = name[0].ToString().ToUpper() + name.Substring(1, name.Length - 1); | |
| // 3 | |
| Console.WriteLine(name); | |
| string[] arr = name.Split(" "); | |
| string joinedWords = string.Join("", arr); | |
| // 4 | |
| Console.WriteLine(joinedWords.Length); | |
| StringBuilder sb = new StringBuilder(name); | |
| index = name.IndexOf("p"); | |
| char p = name[index].ToString().ToUpper()[0]; | |
| sb[index] = p; | |
| name = sb.ToString(); | |
| // 5 | |
| Console.WriteLine(name); | |
| } | |
| } | |
| class EnumsChallenge { | |
| // Create a variable called "playerRank" which has the type of Ranks, and set it to Unranked. | |
| // Display the player's rank in a Console.WriteLine message - a nice & user-friendly one with some string interpolation. | |
| // Find out what the player's next rank will be. This should work no matter what rank the player currently has (eg. if the player starts as Gold rank instead of Unranked). This requires some tricks with integer-enum type conversion! | |
| // Use Console.WriteLine to display a user-friendly message about their next rank. Include both the rank and the number of the rank (eg. "Your next rank is Bronze, which is rank number 2!"). | |
| public enum Ranks | |
| { | |
| Unranked, | |
| Bronze, | |
| Silver, | |
| Gold, | |
| Diamond, | |
| Platinum | |
| } | |
| public static void Solution() { | |
| Ranks playerRank = Ranks.Unranked; | |
| // 1 | |
| Console.WriteLine(playerRank); | |
| // 2 | |
| Console.WriteLine($"player one your rank is {playerRank}"); | |
| int nextRankIndex = (int)playerRank + 1; | |
| Ranks nextRank = (Ranks)nextRankIndex; | |
| // 3 | |
| Console.WriteLine(nextRank); | |
| } | |
| } | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // StringChallenge.Solution(); | |
| EnumsChallenge.Solution(); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment