Exercise: Data Sanitization Pipeline
Problem statement
In financial applications, displaying raw credit card numbers on a user interface is a major security violation. You are building a data sanitization pipeline that must automatically mask the majority of a sensitive string, leaving only the last four characters visible for identification purposes.
Task requirements
Evaluate a given string and replace all characters except the final four with asterisks (
*).If the string is 4 characters or shorter, return it unmodified.
Constraints
You must implement this logic as an extension method for the
stringtype.The method must be placed inside a
staticclass.You must use the
thiskeyword to define the target type of the extension method.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Extension methods must be
staticmethods housed insidestaticclasses.The first parameter of your extension method should be
this string input.You can use a
forloop to iterate through its characters by index.Use string concatenation (
+or+=) to build the masked version of the string piece by piece.
Exercise: Data Sanitization Pipeline
Problem statement
In financial applications, displaying raw credit card numbers on a user interface is a major security violation. You are building a data sanitization pipeline that must automatically mask the majority of a sensitive string, leaving only the last four characters visible for identification purposes.
Task requirements
Evaluate a given string and replace all characters except the final four with asterisks (
*).If the string is 4 characters or shorter, return it unmodified.
Constraints
You must implement this logic as an extension method for the
stringtype.The method must be placed inside a
staticclass.You must use the
thiskeyword to define the target type of the extension method.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Extension methods must be
staticmethods housed insidestaticclasses.The first parameter of your extension method should be
this string input.You can use a
forloop to iterate through its characters by index.Use string concatenation (
+or+=) to build the masked version of the string piece by piece.