Asp.net string truncation function this tutorial first tells you to extract the string in the simplest way, and then write a utility program to intercept the data string.
Asp tutorial. net string truncation Function
In this tutorial, we will first show you the simplest way to take the string and then write a practical program to intercept the data string.
*/
// C #
String mystring = "abc ";
Bool test1 = mystring. substring (2, 1). equals ("c"); // this is true.
// Vb
Substring
Microsoft. visualbasic. left (string, length)
// A simple and intelligent string truncation Function
Protected string getstr (string str)
{
If (str. length> 15)
{
Str = str. substring (0, 15) + "...";
}
Return str;
}
// Intercept an instance
Public static string formatstr (string str, int len)
{
Asciiencoding ascii = new asciiencoding ();
Int templen = 0;
String temps tutorial tring = "";
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 ("& nbsp ;","");
Tempstring = tempstring. replace ("& lt;", "<");
Tempstring = tempstring. replace ("& gt;", "> ");
Tempstring = tempstring. replace ('n'. tostring (), "<br> ");
Return tempstring;
}