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

 

相关文章:

  • 2021-12-12
  • 2021-08-15
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
猜你喜欢
  • 2021-06-23
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-11-12
  • 2022-12-23
相关资源
相似解决方案