我想为String
类编写一个扩展方法,以便如果输入字符串to比提供的长度N
长,则只显示前N
字符。
它看起来是这样的:
public static string TruncateLongString(this string str, int maxLength)
{
if (str.Length <= maxLength)
return str;
else
//return the first maxLength characters
}
我可以使用什么String.*()
方法来仅获取str
的前几个N
字符
https://stackoverflow.com/questions/3566830
复制相似问题