C#去掉字符串头尾指定字符
private void button2_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);
}
最新文章
- juqery 正则表达式的使用
- 【Swift】UILabel 设置内边距
- Java Mybatis 框架入门教程
- PullToRefreshGridView刷新加载
- PHP变量在内存中的存储方式
- STL--迭代器(iterator)
- Java Map 按Key排序和按Value排序
- JavaWeb基础: Tomcat
- 可清空文本的EditText
- http协言和web本质
- Android推断程序前后台状态
- Intent的属性及Intent-filter配置——Component属性
- OC比C中,新增的数据类型
- SQL优化实用方法
- IT咨询顾问:一次吐血的项目救火
- javascript对内容的操作
- 【未解决】centos 6.4 xen4.2 在关机的时候很慢
- 关于0xFFFFFFFF和alpha,温故而知新
- tomcat 在liunx中shutdown后进程仍然存在的两种实用解决办法
- MySQL多表数据记录查询详解