//截取特定长度字符串,不够用...代替
public static string getStr2(string s, int l, string endStr)
{
string temp = s.Substring(0, (s.Length < l + 1) ? s.Length : l + 1);
byte[] encodedBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(temp);
string outputStr = "";
int count = 0;
for (int i = 0; i < temp.Length; i++)
{
if ((int)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 = "";
}
outputStr += endStr;
return outputStr;
}
亲爱的:若该文章解决了您的问题,可否收藏+评论+分享呢?
文章评论 本文章有个评论