码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2018-06-10 15:13:59      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:bsp   void   icon   box   cli   obj   str   div   art   

 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         }

 

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

标签:bsp   void   icon   box   cli   obj   str   div   art   

原文地址:https://www.cnblogs.com/Scholars/p/9162598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!