我相信循环将是最直接和最明确的解决方案,但使用LINQ做它很有趣:
string input = "tom: 1, john: 3, timmy: 5, cid: 8, ad: 88, hid: 99, mn: 33";
char delimiter = ',';
var allParts = input.Split(delimiter);
string result = allParts.Select((item, index) => (index != 0 && (index+1) % 3 == 0)
? item + delimiter + " "
: index != allParts.Count() - 1 ? item + delimiter : item)
.Aggregate((i, j) => i + j);
// result (without a comma after the last item)
// "tom: 1, john: 3, timmy: 5, cid: 8, ad: 88, hid: 99, mn: 33"