前台:
1
<asp:datalist id="pt_zx" runat="server" Width="100%" Height="80px">
2
<ItemTemplate>
3
<table width="100%" border="0" cellspacing="0" cellpadding="0">
4
<tr>
5
<td width="5%"><img src="Images/dec.jpg" width="7" height="8">
6
</td>
7
<td width="95%"><a href='news/news.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id").ToString() %>' target="_blank">
8
后台:2
3
4
5
6
7
8
1
public string CutString1(string str,int length)
2
{
3
int i = 0, j = 0;
4
foreach(char chr in str)
5
{
6
if((int)chr > 127)
7
{
8
i += 2;
9
}
10
else
11
{
12
i ++;
13
}
14
if (i > length)
15
{
16
str = str.Substring(0, j) + "
";
17
break;
18
}
19
j ++;
20
}
21
return str;
22
23
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
谢谢“人在哈尔滨@net”
上面的英文和中文都是同样处理的,这是最好不过的啦