public static void Main()
string tmp = "fdfsdf,2222,,3333,";
Console.WriteLine("method1: " + method1(tmp));
Console.WriteLine("method2: " + method2(tmp));
Console.WriteLine("method3: " + method3(tmp));
Console.WriteLine("============================");
string tmp2 = ",,fdfsdf,2222,,3333,,";
Console.WriteLine("method1: " + method1(tmp2));
Console.WriteLine("method2: " + method2(tmp2));
Console.WriteLine("method3: " + method3(tmp2));
public static string method1(string source)
if (!string.IsNullOrEmpty(tmpclose))
if (tmpclose.IndexOf(',') == 0)
tmpclose = tmpclose.Substring(1, tmpclose.Length - 1);
if (tmpclose.LastIndexOf(',') == tmpclose.Length - 1)
tmpclose = tmpclose.Substring(0, tmpclose.Length - 1);
if (tmpclose.IndexOf(",,") > 0)
tmpclose = tmpclose.Replace(",,", ",");
public static string method2(string source)
if (!string.IsNullOrEmpty(tmpclose))
tmpclose = tmpclose.TrimStart(',').TrimEnd(',').Replace(",,",",");
public static string method3(string source)
if (!string.IsNullOrEmpty(tmpclose))
string[] tmp = tmpclose.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries);
tmpclose = string.Join(",", tmp);