C# 按指定数量从前面或者后面删除字符串

来源:互联网 发布:手机淘宝怎么搜二手的 编辑:程序博客网 时间:2024/05/29 02:47

1 ///
2 /// 从字符串前面删除指定字符个数
3 ///
4 /// 字符串
5 /// 个数
6 /// 返回删除后的字符串
7 public static string RemoveLeft(string s, int len)
8 {
9 return s.PadLeft(len).Remove(0, len);
10 }
11
12 ///
13 /// 从字符串后面删除指定字符个数
14 ///
15 /// 字符串
16 /// 个数
17 /// 返回删除后的字符串
18 public static string RemoveRight(string s, int len)
19 {
20 s = s.PadRight(len);
21 return s.Remove(s.Length - len, len);
22 }

原创粉丝点击