Drill

ProblemsC# › text

Hide most of an email address

easytextStringsParsingC#

A support screen shows enough of the address for an agent to recognise it, without putting the whole thing on screen.

MaskEmail(address: string) → string

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public string MaskEmail(string address) {
    
}

Worked examples

CallResult
MaskEmail("ahmet@example.com")"a****@example.com"
MaskEmail("a@b.com")"a@b.com"
MaskEmail("noatsign")"noatsign"
MaskEmail("@x.com")"@x.com"

Hint

Find the @ first. Everything follows from where it is.

Reference solution in C#
public string MaskEmail(string address) {
    int at = address.IndexOf('@');
    if (at <= 0) return address;
    return address[0] + new string('*', at - 1) + address.Substring(at);
}

The same problem in another language

More text problems in C#