The solutions already given are good.
As seen from the question, since it is required to
bind
the data generated to a
grid
with
each data item into a column
, then I think a
DataTable
with appropriate type for the
Columns
can be generated as follows:
string s1 = "1,dt3435,26/5/2012 ~ 2,dt738,27/5/2012 ~ 3,dt892,26/5/2012";
DataTable values = new DataTable();
values.Columns.Add("F1",typeof(int),null);
values.Columns.Add("F2",typeof(string),null);
values.Columns.Add("F3",typeof(DateTime),null);
values = s1.Split('~').Select( s => {
var fields = s.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
var row = values.NewRow();
if (fields.Length == 3){
row[0]=int.Parse(fields[0].Trim());
row[1]=fields[1].Trim();
row[2] = DateTime.ParseExact(fields[2].Trim(),"d/M/yyyy",
System.Globalization.CultureInfo.InvariantCulture);
}
return row;
}).CopyToDataTable();