Search code examples
c#stringstring-formattingmasking

How to mask string?


I have a string with value "1131200001103".

How can I display it as a string in this format "11-312-001103" using Response.Write(value)?

Thanks


Solution

  • This produces the required result

    string result = Int64.Parse(s.Remove(5,2)).ToString("00-000-000000");
    

    assuming that you want to drop 2 characters at the position of the 2 first nulls.