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

C# 字符串Trim进阶

时间:2019-06-28 22:50:54      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:code   显示   去掉   共和国   ring   bsp   nbsp   event   pre   

private void button1_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);                        
        }

 

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

 

C# 字符串Trim进阶

标签:code   显示   去掉   共和国   ring   bsp   nbsp   event   pre   

原文地址:https://www.cnblogs.com/zhang1f/p/11104960.html

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