Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of ToUpper and Trim methods
What is the output of this C# code snippet?
C Sharp (C#)
string text = " Hello World ";
string result = text.Trim().ToUpper();
Console.WriteLine(result);Attempts:
2 left
💡 Hint
Remember that Trim removes spaces at the start and end, and ToUpper converts all letters to uppercase.
✗ Incorrect
The Trim method removes spaces from both ends of the string, so " Hello World " becomes "Hello World". Then ToUpper converts all letters to uppercase, resulting in "HELLO WORLD".
❓ Predict Output
intermediate2:00remaining
Result of Replace and Substring methods
What will be printed by this C# code?
C Sharp (C#)
string s = "apple pie"; string newS = s.Replace("pie", "tart").Substring(0, 5); Console.WriteLine(newS);
Attempts:
2 left
💡 Hint
Replace changes "pie" to "tart" and Substring(0,5) takes the first 5 characters.
✗ Incorrect
Replace changes "apple pie" to "apple tart". Then Substring(0,5) extracts characters from index 0 to 4, which is "apple".
❓ Predict Output
advanced2:00remaining
Output of IndexOf and Contains methods
What is the output of this code?
C Sharp (C#)
string phrase = "Learning C# is fun!"; int index = phrase.IndexOf("C#"); bool hasFun = phrase.Contains("fun"); Console.WriteLine($"{index} {hasFun}");
Attempts:
2 left
💡 Hint
IndexOf returns the first position of the substring or -1 if not found. Contains returns true if substring exists.
✗ Incorrect
The substring "C#" starts at index 9 in the phrase. The phrase contains "fun", so Contains returns true. Output is "9 True".
❓ Predict Output
advanced2:00remaining
Effect of ToLower and StartsWith methods
What does this code print?
C Sharp (C#)
string input = "OpenAI ChatGPT"; string lower = input.ToLower(); bool starts = lower.StartsWith("open"); Console.WriteLine(starts);
Attempts:
2 left
💡 Hint
ToLower converts all letters to lowercase. StartsWith checks if string begins with given substring.
✗ Incorrect
After ToLower, the string is "openai chatgpt" which starts with "open". So StartsWith returns true, printed as "True".
❓ Predict Output
expert3:00remaining
Output of complex string manipulation
What is the output of this C# code?
C Sharp (C#)
string s = " CSharp Programming "; string result = s.Trim().Replace(" ", "_").ToLower(); Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Trim removes spaces at ends, Replace changes spaces to underscores, ToLower makes all letters lowercase.
✗ Incorrect
Trim removes spaces at start and end, so "CSharp Programming" remains. Replace changes spaces to underscores: "CSharp_Programming". ToLower converts to "csharp_programming".