Async Text Sanitizer — Read, Normalize, Save
Scenario: A support chat export is copied as multi-line text with extra spaces and special symbols. You must sanitize it asynchronously and return a single normalized string. What to implement: - ChatSanitizer.NormalizeAsync(string rawText) Rules: - Use await Task.Yield() to simulate asynchronous work per line - Trim each line, remove empty lines - Replace multiple spaces with single space - Keep unicode and emoji - Return joined lines with '\n' ✅ Student task: Implement ONLY the TODO method.
using System; // basic types
using System.Linq; // Split / LINQ
using System.Text.RegularExpressions; // regex for spaces
using System.Threading.Tasks; // Task / async
namespace ItTechGenie.M1.AsyncAwait.Q1
{
public static class ChatSanitizer
{
// ✅ TODO: Student must implement only this method
public static async Task<string> NormalizeAsync(string rawText)
{
// TODO:
// - validate rawText not null
// - split by newlines
// - await Task.Yield() per line (simulate async)
// - trim, skip empty
// - replace multiple spaces with single space
// - join using "\n"
throw new NotImplementedException();
}
}
internal class Program
{
static async Task Main()
{
var raw = " Ticket: #A-901 \n User : Sana @ Chennai ✅ \n\n Issue: Login failed!!! \n Note : Reset password @ 10:30 PM ";
var normalized = await ChatSanitizer.NormalizeAsync(raw);
Console.WriteLine(normalized);
}
}
}