C# StringBuilder – 2 Questions per Major API (Moderate–High)
This sheet focuses on performance-aware and scenario-based coding questions using System.Text.StringBuilder.
Append
- Build a transaction log from 1 million messages without memory pressure.
- Read words until "STOP" and build the sentence efficiently.
AppendLine
- Generate a multi-line error report.
- Format stack-trace style output.
AppendFormat
- Build an invoice statement using placeholders.
- Create aligned columns for console output.
Insert
- Insert commas every 3 digits.
- Inject timestamps at the beginning of each log entry.
Remove
- Remove sensitive tokens by index.
- Delete alternate characters.
Replace
- Mask credit-card numbers.
- Replace forbidden chat words.
Clear
- Reuse builder inside loops.
- Reset CSV buffer after every row.
ToString
- Convert large builder to output chunks.
- Produce immutable snapshots.
Capacity
- Pre-allocate capacity for imports.
- Log resizing events.
EnsureCapacity
- Reserve memory before appending.
- Optimize JSON building for known size.
Length
- Truncate output beyond 10,000 chars.
- Validate maximum XML size.
CopyTo
- Copy part into a char buffer.
- Stream content into a file writer.
Equals
- Compare two builders for content equality.
- Detect identical logs.
AppendJoin
- Join thousands of values efficiently.
- Build pipe-separated exports.
Append(char, int)
- Generate padding spaces.
- Build ASCII boxes.
Insert(int, string)
- Inject separators into phone numbers.
- Add markers at specific indices.
Remove(int, int)
- Strip HTML tags by index ranges.
- Delete invalid data blocks.
Replace(string, string)
- Convert markup tags to HTML entities.
- Replace environment tokens.