也许我在这里分享的这两种小方法对某人很方便。
public static string Left(this string input, int length) {
string result = input;
if (input != null && input.Length > length) {
result = input.Substring(0, length);
}
return result;
}
public static string Right(this string input, int length) {
string result = input;
if (input != null && input.Length > length) {
result = input.Substring(input.Length - length, length);
}
return result;
}