# Region format the string and take the strLength digit before the string. For others, use... instead of. to calculate the string length. Two Chinese characters, one letter and one byte FormatString (string str, int len)
/// <Summary>
/// Format the string and take the strLength digit before the string. For others, use... instead of. to calculate the string length. Two Chinese characters, one letter and one byte
/// </Summary>
/// <Param name = "str"> string </param>
/// <Param name = "strLength"> String Length </param>
/// <Returns> </returns>
Public static string FormatStr (string str, int len)
{
ASCIIEncoding ascii = new ASCIIEncoding ();
Int tempLen = 0;
String tempString = "";
Byte [] s = ascii. GetBytes (str );
For (int I = 0; I <s. Length; I ++)
{
If (int) s [I] = 63)
{
TempLen + = 2;
}
Else
{
TempLen + = 1;
}
Try
{
TempString + = str. Substring (I, 1 );
}
Catch
{
Break;
}
If (tempLen> len)
Break;
}
// If yes, add half ellipsis
Byte [] mybyte = System. Text. Encoding. Default. GetBytes (str );
If (mybyte. Length> len)
TempString + = "...";
TempString = tempString. Replace ("","");
TempString = tempString. Replace ("<", "<");
TempString = tempString. Replace (">", "> ");
TempString = tempString. Replace ('\ n'. ToString (), "<br> ");
Return tempString;
}
# Endregion