C# 移除字符串头尾指定字符


 1  private void button1_Click(object sender, EventArgs e)
 2         {//去掉字符串头尾指定字符
 3             string MyInfo= "--中华人民共和国--";
 4             //显示 "中华人民共和国"
 5             MessageBox.Show(MyInfo.Trim(new char[1] { '-' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);            
 6             MyInfo = ",-中华人民共和国-,-";
 7             //显示 "中华人民共和国"
 8             MessageBox.Show(MyInfo.Trim(new char[2] { '-', ',' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                        
 9             MyInfo = "--中华人民共和国--";
10             //显示 "中华人民共和国--"
11             MessageBox.Show(MyInfo.TrimStart(new char[1] { '-' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                        
12             MyInfo = ",-中华人民共和国-,-";
13             //显示 "中华人民共和国-,-"
14             MessageBox.Show(MyInfo.TrimStart(new char[2] { '-', ',' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                        
15             MyInfo = "--中华人民共和国--";
16             //显示 "--中华人民共和国"
17             MessageBox.Show(MyInfo.TrimEnd(new char[1] { '-' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                        
18             MyInfo = ",-中华人民共和国-,-";
19             //显示 ",-中华人民共和国"
20             MessageBox.Show(MyInfo.TrimEnd(new char[2] { '-', ',' }), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                        
21         }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM