有个字符串  ,1,2,3, 怎么样把最前面的逗号和最后面的逗号去掉.
变成1,2,3  是ASP.NET

解决方案 »

  1.   

    string str=",1,2,3,";
    str=str.Trim(',');
      

  2.   

    good,去查了下msdn。
    C#
    public string Trim (
        params char[] trimChars
    )

    trimChars
    要移除的 Unicode 字符数组或 空引用(在 Visual Basic 中为 Nothing)。 返回值
    从当前 String 对象的开始和末尾移除 trimChars 参数中字符的所有匹配项后保留的字符串。如果 trimChars 为 空引用(在 Visual Basic 中为 Nothing),则改为移除空白字符。 
     备注 
    Trim 方法从当前字符串移除 trimChars 参数中的所有前导字符和尾部字符。遇到不在 trimChars 中的字符时,每个前导裁剪操作和尾部裁剪操作都会停止。例如,如果当前字符串为“123abc456xyz789”并且 trimChars 包含从“1”到“9”的数字,则 Trim 方法返回“abc456xyz”。有关将哪些 Unicode 字符归类为空白字符的更多信息,请参见 String.Trim 方法重载的“备注”部分。 示例 
    下面的代码示例演示 Trim(Char[]) 方法重载。
    using System;class stringTrim2 {
        public static void Main() {
            String str1 = "*;|@123***456@|;*";
        String delim = "*;|@";
        String str2 = str1.Trim(delim.ToCharArray());    Console.WriteLine("Delimiters:      {0}", delim);
        Console.WriteLine("Original string: {0}", str1);
        Console.WriteLine("Trimmed string:  {0}", str2);
        }
    }
    // This code example displays the following:
    //
    // Delimiters:      *;|@
    // Original string: *;|@123***456@|;*
    // Trimmed string:  123***456
      

  3.   

    string str = ",1,2,3,";
    str k = str.Replace(",", "");
    k = 123;