如何从字符串中删除结尾逗号

问题描述:

public string display()
    {
        string st="";
        DataTable dt= (DataTable)ViewState["CurrentData"];
        for (int i = 0; i < dt.Rows.Count ; i++)
        {
            st += dt.Rows[i]["item"].ToString() + ",";
        }

        return st;
    }


这是我的函数,它以字符串格式存储值
例如:-abc @ gmail.com,xya @ yahoo.com,dfd @ gmail.com,

如何从字符串中删除最后一个逗号
例如:-abc @ gmail.com,xya @ yahoo.com,dfd @ gmail.com

请帮我...


This is my function who stores values in string format
for eg:- abc@gmail.com,xya@yahoo.com,dfd@gmail.com,

How can i remove the last comma from the string
for eg:- abc@gmail.com,xya@yahoo.com,dfd@gmail.com

Pls help me...

string finalvalue = string.Empty;
finalvalue = lblSelected.Text.Substring(0, lblSelected.Text.Length - 1);



谢谢
Ashish



Thanks
Ashish


st = st.Remove(st.Length-1,1);
st = st.Remove(st.Length - 1, 1);


st = st.Substring(0,st.Length- 1);
st=st.Substring(0,st.Length-1);