字符串STR=“AS,BD,DFDAF,,,”
想获取STR=“AS,BD,DFDAF”把后面的逗号都过滤掉。

解决方案 »

  1.   


    /// <summary>
    /// 截掉字符串后边的逗号
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static string TrimLastChar(string str)
    {
    if (str.ToString() != "" || str != null)
    {
    char[] arrChar = str.ToCharArray();
    bool isEnd = true;
    int i; if(str == "" || str == null)
    {
    return "";
    } for(i=arrChar.Length-1; i>-1; i--)
    {
    if(arrChar[i] == ',' && isEnd)
    {
    continue;
    } isEnd = false;
    break;
    }
    str = str.Substring(0, i+1);
    if(str.EndsWith("."))
    {
    str = str.Substring(0, str.Length-1);
    }
    }
    else
    {
    str = "";
    } return str;
    }