我写了个截取字符串的方法
/// <summary>
/// 截获定长的字符串
/// </summary>
/// <param name="source">源字符串</param>
/// <param name="length">需要截获的长度</param>
/// <param name="postfix">如果字符串被截短,需要添加什么样的后缀</param>
/// <returns>截获后的字符串</returns>
static public string FixLenth(string source, int length, string postfix)
{
if (source == null)
throw new ArgumentNullException("source");
if (postfix == null)
postfix = "..."; if (length < postfix.Length)
throw new ArgumentOutOfRangeException("length");
int postfixLength = System.Text.Encoding.GetEncoding("GB2312").GetByteCount(postfix);
int srcLength = System.Text.Encoding.GetEncoding("GB2312").GetByteCount(source); if (srcLength > length)
{
for (int i = source.Length; i > 0; i--)
{
srcLength = System.Text.Encoding.GetEncoding("GB2312").GetByteCount(source.Substring(0, i)); if (srcLength <= length - postfixLength)
return source.Substring(0, i) + postfix;
}
return "";
}
else
return source;
}为什么这样引用就可以
<td width="225" class="style19" align="left"><%#Global.FixLenth(Eval("ProgramComment").ToString(), 100, "...")%></td>
但这样引用就不行,返回是空。
<td class="style19" style="height: 100%" ><a><%#Global.FixLenth("Aam:这是一张以我们之前所打造的那种与众不同的创作风格为根基,然后在整体乐风呈现上较前作来得更加性感迷人,更加强烈震撼,甚至在歌曲表现上都显得份外深层晦暗的作品.", 20, "...")%></a></td>
解决方案 »
- 这是要逆天啊。。。。。浏览器不兼容的一个问题
- server 2008的系统,安装过sql server2008,怎么装2005?
- .net 批量发送邮件很慢
- 为什么用GDI+在网页上画完图以后,其它的控件就都没了
- 弱弱地问一下,在ASP.NET中怎么使用CSS文件啊?
- [请问]object 定义的方法,或者变量是什么意思?怎么用的
- HttpRequest怎么把URL信息加载进去
- windows自带smtp发送邮件的问题,找了好多都没能解决
- 如何控制DataGrid的大小
- 一个空间多个网站的问题
- ASP.NEt中的DataGrid???
- asp.net实现透明图片的输出,图片背景变黑色问题!(C#) 特急!
不能直接放到a里面。
显然对<%# %>
<%= %>
不了解