Search⌘ K
AI Features

Solution: Data Sanitization Pipeline

Explore how to implement a data sanitization pipeline in C# by creating an extension method to mask sensitive strings. Understand the use of file-scoped namespaces, static classes, and the this modifier to extend string functionality. This lesson helps you securely process data by masking parts of strings like card numbers, preventing errors and ensuring privacy within your applications.

We'll cover the following...
C# 14.0
namespace Finance.Utilities;
public static class StringExtensions
{
public static string MaskSensitiveData(this string input)
{
if (string.IsNullOrEmpty(input) || input.Length <= 4)
{
return input;
}
string result = "";
int maskLength = input.Length - 4;
// Manually build the string using basic loops and concatenation
for (int i = 0; i < input.Length; i++)
{
if (i < maskLength)
{
result += "*";
}
else
{
result += input[i];
}
}
return result;
}
}
...