string temp = string.Empty; // int i = value.Length; if (value.Length == 3 || value.Length == 7) { if (temp.Length == 0) { temp = value; } temp += "-"; } else { temp = value; } ((Entry)sender).Text = temp;