Chinese Character | display | page | string | String The following is code, OH, relatively simple, mainly to distinguish between Chinese characters and letters, or a whole is a letter, a full of Chinese characters in the two records will be more ugly, the length of the whole character only half of the whole Chinese characters show ... Number.
public static string StringFormat (String str,int N)
{
///
format string length, out of partial display ellipsis, distinguishing characters from letters. Kanji 2 bytes, alphanumeric one byte
///
String temp=string. Empty;
if (System.Text.Encoding.Default.GetByteCount (str) <=n)//If the length is smaller than the desired length n, return the original string
{
return str;
}
Else
{
int t=0;
Char[] Q=str. ToCharArray ();
for (int i=0;i<q.length&&t<n;i++)
{
if (int) q[i]>=0x4e00 && (int) q[i]<=0x9fa5)//whether Chinese characters
{
Temp+=q[i];
t+=2;
}
Else
{
Temp+=q[i];