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

/// <summary>
/// 从字符串前面删除指定字符个数
/// </summary>
/// <param name="s">字符串</param>
/// <param name="len">个数</param>
/// <returns>返回删除后的字符串</returns>
public static string RemoveLeft(string s, int len)
{
return s.PadLeft(len).Remove(0, len);
}

/// <summary>
/// 从字符串后面删除指定字符个数
/// </summary>
/// <param name="s">字符串</param>
/// <param name="len">个数</param>
/// <returns>返回删除后的字符串</returns>
public static string RemoveRight(string s, int len)
{
s = s.PadRight(len);
return s.Remove(s.Length - len, len);
}

 

posted @ 2022-04-02 16:37  进步者One  阅读(264)  评论(0编辑  收藏  举报