这类似于最近的question I asked,但现在我很想知道字符串修剪函数的真正替换,它将从字符串中删除“字符串”的“任意”。此外,为了使它成为基本Trim()的功能,让它接受一个要修剪的字符串数组。
那里有任何现有的实现吗?我猜一些.NET实用程序库会有这个。
答案 0 :(得分:1)
您可以创建扩展方法来执行此操作。创建你的重载,然后做你想要的。有很多方法可以像正则表达式或标准字符串函数一样,如substring
public static class StringExtensions
{
public string Trim(this string input, string remove)
{
//..Do your work here
}
public string TrimStart(this string input, string remove)
{
//..Do your work here
}
public string TrimEnd(this string input, string remove)
{
//..Do your work here
}
}