How do I hide a row?
4 answers
Any reason you don't want to just use Substring
?
string dashed = text.Substring(0, 2) + "-" +
text.Substring(2, 3) + "-" +
text.Substring(7);
Or:
string dashed = string.Format("{0}-{1}-{2}", text.Substring(0, 2),
text.Substring(2, 3), text.Substring(7));
(I'm guessing it's overlooked that you missed two of the 0s? Not clear which 0s are, admittedly ...)
Obviously, you have to check that the string is of the correct length first ...
+12
source to share
You can try regex and put it in ToMaskedString () extension method
public static class StringExtensions
{
public static string ToMaskedString(this String value)
{
var pattern = "^(/d{2})(/d{3})(/d*)$";
var regExp = new Regex(pattern);
return regExp.Replace(value, "$1-$2-$3");
}
}
Then call
respne.Write(value.ToMaskedString());
+2
source to share