0
0
C Sharp (C#)programming~20 mins

String searching and extraction in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Search Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of IndexOf and Substring
What is the output of this C# code snippet?
C Sharp (C#)
string text = "Hello, world!";
int index = text.IndexOf('o');
string result = text.Substring(index, 5);
Console.WriteLine(result);
Aow ,o
Bo, worl
Co, wo
Dlrow ,o
Attempts:
2 left
💡 Hint
Remember that Substring's second parameter is length, not end index.
Predict Output
intermediate
2:00remaining
Extracting domain from email
What is the output of this C# code?
C Sharp (C#)
string email = "user@example.com";
int atPos = email.IndexOf('@');
string domain = email.Substring(atPos + 1);
Console.WriteLine(domain);
Auser@
Buser@example.com
C@example.com
Dexample.com
Attempts:
2 left
💡 Hint
Substring starting after '@' extracts the domain part.
Predict Output
advanced
2:00remaining
Using Regex to extract numbers
What does this C# code print?
C Sharp (C#)
using System.Text.RegularExpressions;

string input = "Order1234: 56 items";
var match = Regex.Match(input, @"\d+");
Console.WriteLine(match.Value);
A1234
B56
COrder1234
Ditems
Attempts:
2 left
💡 Hint
Regex.Match finds the first sequence of digits.
Predict Output
advanced
2:00remaining
Extracting substring between two characters
What is the output of this C# code?
C Sharp (C#)
string data = "[start]middle[end]";
int startIndex = data.IndexOf('[') + 1;
int endIndex = data.IndexOf(']');
string extracted = data.Substring(startIndex, endIndex - startIndex);
Console.WriteLine(extracted);
Astart]middle
Bstart
Cstart]middle[end
Dstart]middle[end]
Attempts:
2 left
💡 Hint
Substring extracts from after '[' up to before ']'.
🧠 Conceptual
expert
2:00remaining
Behavior of String.IndexOf with missing substring
What is the value of variable 'pos' after running this C# code?
C Sharp (C#)
string text = "hello world";
int pos = text.IndexOf("xyz");
A-1
B0
Cthrows an exception
Dlength of the string
Attempts:
2 left
💡 Hint
IndexOf returns -1 if substring is not found.