Because Chinese and English take different positions, 10 English letters can be displayed for one location that displays five Chinese characters,
This string operation function is easy to use and is written in csdn.
/// Content summary: truncates a string by byte.
/// </Summary>
Public static string getsubstring (string mtext, int startindex, int bytecount)
{
If (bytecount <1) return string. empty;
If (system. Text. encoding. Default. getbytecount (mtext) <= bytecount)
{
Return mtext;
}
Else
{
If (startindex = 0)
{
Byte [] txtbytes = system. Text. encoding. Default. getbytes (mtext );
Byte [] newbytes = new byte [bytecount];
For (INT I = 0; I <bytecount; I ++)
Newbytes [I] = txtbytes [I];
Return System. Text. encoding. Default. getstring (newbytes );
}
Else
{
String TMP = getsubstring (mtext, 0, startIndex-1 );
Mtext = mtext. substring (TMP. Length );
Return getsubstring (mtext, 0, bytecount );
}
}
}
Public static string getsubstring (string mtext, int startindex)
{
Return getsubstring (mtext, startindex, system. Text. encoding. Default. getbytecount (mtext)-startindex + 1 );
}
usage:
enter this field in the Data Binding area, instead of the original <% eval ("text") %>
<% # getsubstring (databinder. eval (container. dataitem, "text "). tostring (), 0, 10) %>