您的位置:首页 > 编程语言 > C#

C#去掉字符串头尾指定字符

2010-06-05 18:15 344 查看
private void button2_Click(object sender, EventArgs e)
{//去掉字符串头尾指定字符
string MyInfo= "--中华人民共和国--";
//显示 "中华人民共和国"
MessageBox.Show(MyInfo.Trim(new char[1] { '-' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MyInfo = ",-中华人民共和国-,-";
//显示 "中华人民共和国"
MessageBox.Show(MyInfo.Trim(new char[2] { '-', ',' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MyInfo = "--中华人民共和国--";
//显示 "中华人民共和国--"
MessageBox.Show(MyInfo.TrimStart(new char[1] { '-' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MyInfo = ",-中华人民共和国-,-";
//显示 "中华人民共和国-,-"
MessageBox.Show(MyInfo.TrimStart(new char[2] { '-', ',' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MyInfo = "--中华人民共和国--";
//显示 "--中华人民共和国"
MessageBox.Show(MyInfo.TrimEnd(new char[1] { '-' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MyInfo = ",-中华人民共和国-,-";
//显示 ",-中华人民共和国"
MessageBox.Show(MyInfo.TrimEnd(new char[2] { '-', ',' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐