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

  1. Validate a password where length ≥ 10 after trimming spaces.
  2. Find the longest word in a sentence without using Split.

Indexer

  1. Count vowels using indexing only.
  2. Reverse a string without converting to char[].

Contains

  1. Detect if a log line contains "ERROR" ignoring case.
  2. Block forbidden words from user input.

IndexOf

  1. Find first digit in a string.
  2. Find first repeated character.

LastIndexOf

  1. Extract file extension from a path.
  2. Get last word in a sentence.

StartsWith

  1. Validate URL starts with http or https.
  2. Detect comment lines starting with //.

EndsWith

  1. Validate .csv file upload.
  2. Detect sentence ending punctuation.

Substring

  1. Mask middle digits of ID numbers.
  2. Extract date parts from yyyy-MM-dd.

Replace

  1. Censor bad words.
  2. Replace digits with *.

Insert

  1. Insert hyphens every 4 digits.
  2. Insert commas into a number manually.

Remove

  1. Remove vowels by index scanning.
  2. Remove duplicate characters by position.

Split

  1. Parse CSV with empty values.
  2. Tokenize sentence on punctuation.

Join

  1. Join words with |.
  2. Build pipe-separated report lines.

Trim

  1. Clean user input lines.
  2. Detect blank entries.

TrimStart

  1. Remove leading zeros.
  2. Remove leading tabs/spaces.

TrimEnd

  1. Remove trailing punctuation.
  2. Remove trailing slashes from URLs.

PadLeft

  1. Format invoice numbers to 8 digits.
  2. Right-align numbers in reports.

PadRight

  1. Create fixed-width columns.
  2. Align console tables.

ToUpper

  1. Convert keywords to uppercase only.
  2. Capitalize first letter of each word.

ToLower

  1. Normalize emails.
  2. Case-insensitive username match.

ToUpperInvariant

  1. Normalize IDs across cultures.
  2. Compare SKU codes culture-safe.

ToLowerInvariant

  1. Dictionary key normalization.
  2. Case-insensitive hashing.

Equals

  1. Compare two strings ignoring case.
  2. Validate OTP input.

Compare

  1. Sort names alphabetically.
  2. Manual min/max string finder.

CompareOrdinal

  1. Secure token comparison.
  2. Binary-safe ordering.

IsNullOrEmpty

  1. Validate mandatory fields.
  2. Filter invalid records.

IsNullOrWhiteSpace

  1. Reject blank usernames.
  2. Clean text lines.

Normalize

  1. Compare accented characters.
  2. Detect Unicode lookalikes.

ToCharArray

  1. Character frequency counter.
  2. Caesar cipher implementation.

Concat

  1. Build audit message.
  2. Append suffix/prefix safely.

Format

  1. Generate invoice lines.
  2. Aligned reports.

Enumeration

  1. Count upper/lower/digits.
  2. Validate password complexity.