1. 程式人生 > >C# 按指定數量從前面或者後面刪除字串

C# 按指定數量從前面或者後面刪除字串

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 }