C# String Functions – 2 Questions per Major API (Moderate–High)
This sheet contains scenario-based coding questions covering most commonly used System.String APIs.
Length
- Validate a password where length ≥ 10 after trimming spaces.
- Find the longest word in a sentence without using Split.
Indexer
- Count vowels using indexing only.
- Reverse a string without converting to char[].
Contains
- Detect if a log line contains "ERROR" ignoring case.
- Block forbidden words from user input.
IndexOf
- Find first digit in a string.
- Find first repeated character.
LastIndexOf
- Extract file extension from a path.
- Get last word in a sentence.
StartsWith
- Validate URL starts with http or https.
- Detect comment lines starting with //.
EndsWith
- Validate .csv file upload.
- Detect sentence ending punctuation.
Substring
- Mask middle digits of ID numbers.
- Extract date parts from yyyy-MM-dd.
Replace
- Censor bad words.
- Replace digits with *.
Insert
- Insert hyphens every 4 digits.
- Insert commas into a number manually.
Remove
- Remove vowels by index scanning.
- Remove duplicate characters by position.
Split
- Parse CSV with empty values.
- Tokenize sentence on punctuation.
Join
- Join words with |.
- Build pipe-separated report lines.
Trim
- Clean user input lines.
- Detect blank entries.
TrimStart
- Remove leading zeros.
- Remove leading tabs/spaces.
TrimEnd
- Remove trailing punctuation.
- Remove trailing slashes from URLs.
PadLeft
- Format invoice numbers to 8 digits.
- Right-align numbers in reports.
PadRight
- Create fixed-width columns.
- Align console tables.
ToUpper
- Convert keywords to uppercase only.
- Capitalize first letter of each word.
ToLower
- Normalize emails.
- Case-insensitive username match.
ToUpperInvariant
- Normalize IDs across cultures.
- Compare SKU codes culture-safe.
ToLowerInvariant
- Dictionary key normalization.
- Case-insensitive hashing.
Equals
- Compare two strings ignoring case.
- Validate OTP input.
Compare
- Sort names alphabetically.
- Manual min/max string finder.
CompareOrdinal
- Secure token comparison.
- Binary-safe ordering.
IsNullOrEmpty
- Validate mandatory fields.
- Filter invalid records.
IsNullOrWhiteSpace
- Reject blank usernames.
- Clean text lines.
Normalize
- Compare accented characters.
- Detect Unicode lookalikes.
ToCharArray
- Character frequency counter.
- Caesar cipher implementation.
Concat
- Build audit message.
- Append suffix/prefix safely.
Format
- Generate invoice lines.
- Aligned reports.
Enumeration
- Count upper/lower/digits.
- Validate password complexity.