I have ID as 10 digits int ex: 1023456789 and I need to set DataGridView format to have there "102-34567 add. 89".
string.Format("###-##### add. ##") doesn't work.
So how to do that?
var result = 1023456789.ToString("###-##### add\\. ##");
DataGridView though, so there should not be any String.Format or ToString call at all.If the ID length is always 10 characters,you can use String.Insert(Int32, String)
string s = "1023456789";
string resultt = s.Insert(3, "_").Insert(9, " add. "); //"102-34567 add. 89"
string?String.Formatworks. It's job is to to format a non-string value as a string. It doesn't work with string inputs, nor is it meant to. What did you actually try?DefaultCellStyle.Formatproperty of the column. You don't callString.Formatyourself. The grid callsToStringon the data and passes the format specifier that you provided.