zoukankan      html  css  js  c++  java
  • 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         }
  • 相关阅读:
    测试一下你的T-SQL基础知识-count
    测试一下你的T-SQL基础知识-subquery
    Microsoft SQL Server 2012 管理 (2): Auditing
    Webpack
    react
    Webpack 傻瓜式指南(一)
    谈谈react-router学习
    使用Flexible 实现手淘H5 页面的终端适配学习
    Promise 让异步更优
    基于LeanCloud云引擎的Web全栈方案
  • 原文地址:https://www.cnblogs.com/Scholars/p/9162598.html
Copyright © 2011-2022 走看看