public static string GetString(this HtmlHelper htmlHelper, string s, int l, string endStr)
{
string temp = s.Substring(0, (s.Length < l + 1) ? s.Length : l + 1);
byte[] encodedBytes = Encoding.ASCII.GetBytes(temp);
string outputStr = string.Empty;
int count = 0;
for (int i = 0; i < temp.Length; i++)
{
if (encodedBytes[i] == 63)
{
count += 2;
}
else
{
count += 1;
}
if (count <= l - endStr.Length)
{
outputStr += temp.Substring(i, 1);
}
else if (count > l)
{
break;
}
}
if (count <= l)
{
outputStr = temp;
endStr = string.Empty;
}
outputStr += endStr;
return outputStr;
}
时间: 2024-10-08 22:23:24