C # a string of numbers "1122331111155", which must be output to the DataGridview control, but must be read one by one. If the previous number is the same as the next one, it is arranged in a column, not the same, A column is also arranged. For example, "1122331111155", the output result is: Column 1: 11, column 2: 22, column 3: 33, column 4: 11111, column 5: 55. As follows: string numberStr = "1122331111155"; string temp = string. empty; string column = string. empty; List <string> lstColumn = new List <string> (); numberStr. toCharArray (). toList (). forEach (char c) =>{ if (string. isNullOrEmpty (temp) {temp = c. toString ();} if (temp = c. toString () {column + = c;} else {lstColumn. add (column); temp = c. toString (); column = temp ;}}); lstColumn. add (column); lstColumn. forEach (string columnName) => {this. dataGridView1.Columns. add (new maid (), Name = columnName}) ;}; MatchCollection mc = Regex. matches ("1122331111155 ",@"(.) \ 1 * "); List <string> columns = new List <string> (); foreach (Match m in mc) {columns. add (m. value);} columns. forEach (string columnName) => {this. dataGridView1.Columns. add (new maid (), Name = columnName });});