C# Replace two specific commas in a string with many commas

Posted by Hal on Stack Overflow See other posts from Stack Overflow or by Hal
Published on 2012-10-04T21:36:12Z Indexed on 2012/10/04 21:37 UTC
Read the original article Hit count: 128

Filed under:
|

I am trying to change the date format in each line from commas to hyphens. The index of the comma separating the month and day day and year varies.

   lines_in_List[i] = lines_in_List[i].Insert(0, cnt + ","); // Insert Draw # in 1st column

   string one_line = lines_in_List[i];
   // 0,5,1,2012,1,10,19,16,6,36,,,
   // 1,11,5,2012,49,35,23,37,38,28,,,
   // 2,12,10,2012,8,52,53,54,47,15,,,
   //  ^-^--^ replace the ',' with a '-'.

   StringBuilder changed = new StringBuilder(one_line);
   changed[3] = '-';
   changed[5] = '-';
   changed[3] = '-';
   lines_in_List[i] = changed.ToString();
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about string