最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net字符串截取函数
时间:2010-08-24 编辑:简简单单 来源:一聚教程网
asp教程.net字符串截取函数
本教程先是告诉你用最简单的方法取对字符串进行截取,再后面写了一个实用的程序来对数据进行字符串截取哦。
*/
//c#
string mystring = "abc";
bool test1 = mystring.substring(2, 1).equals("c"); // this is true.//vb
substring
microsoft.visualbasic.left(string, length)
//一个简单智能一点的字符串截取函数protected string getstr(string str)
{if (str.length > 15)
{
str = str.substring(0, 15) + "...";
}
return str;
}
//截取实例public static string formatstr(string str, int len)
{
asciiencoding ascii = new asciiencoding();
int templen = 0;
string temps教程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;
}
//如果截过则加上半个省略号
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(), "
");
return tempstring;
}
相关文章
- asp.net字符串截取函数介绍 04-14
- asp.net 字符串截取函数 07-09
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18