读取标题太长导致前台变形

dmlions 2010-06-01 01:54:02
数据库里一个标题有20个字,在前台读取后页面变形
怎么截取前10个字,后面的用...代替
...全文
97 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
dmlions 2010-06-01
  • 打赏
  • 举报
回复
SQL没学好,复杂的语句不会写,感谢6L
lya121 2010-06-01
  • 打赏
  • 举报
回复
都喜欢玩SQL啊

如果在做列表页的时候希望过长标题超长部分以“…”代替
但是又希望在鼠标移到该标题的时候出现提示,而提示部分是完整的标题呢,又去查一次?
aiguo0713 2010-06-01
  • 打赏
  • 举报
回复
select substring('1234567891111',0,11)+'...'
橙宝宝 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ca3355 的回复:]
select id,substring(name,0,10)+'...' as name form 表名
[/Quote]
这个是你想要的
正在加载昵称 2010-06-01
  • 打赏
  • 举报
回复
21改成自己想要的字符数[Quote=引用 5 楼 lzw1987andy 的回复:]
SQL code
select (case when len(字段名)>=21 then substring(字段名,1,21)+'...' else vDownLoadName end) as 别名 from 表名
[/Quote]
winner2050 2010-06-01
  • 打赏
  • 举报
回复
#region 截短字串的函数,兼容中英文
/// <summary>
/// 截短字串的函数,兼容中英文
/// </summary>
/// <param name="mText">要加工的字串</param>
/// <param name="byteCount">长度</param>
/// <returns>被加工过的字串</returns>
public static string Left(string mText, int byteCount)
{
if (byteCount < 1)
return mText;

if (System.Text.Encoding.Default.GetByteCount(mText) <= byteCount)
{
return mText;
}
else
{
byte[] txtBytes = System.Text.Encoding.Default.GetBytes(mText);
byte[] newBytes = new byte[byteCount - 4];

for (int i = 0; i < byteCount - 4; i++)
{
newBytes[i] = txtBytes[i];
}
string OutPut = System.Text.Encoding.Default.GetString(newBytes) + "...";
if (OutPut.EndsWith("?...") == true)
{
OutPut = OutPut.Substring(0, OutPut.Length - 4);
OutPut += "...";
}
return OutPut;
}
}
#endregion
正在加载昵称 2010-06-01
  • 打赏
  • 举报
回复
select (case when len(字段名)>=21 then substring(字段名,1,21)+'...' else vDownLoadName end) as 别名 from 表名
橙宝宝 2010-06-01
  • 打赏
  • 举报
回复
select id,substring(name,0,10) as name form 表名
空心兜兜 2010-06-01
  • 打赏
  • 举报
回复

select convert(nchar(20),title,40)+'...' as newtitle from [table]
空心兜兜 2010-06-01
  • 打赏
  • 举报
回复
select convert(nchar(20),title,40) as newtitle from [table]
lya121 2010-06-01
  • 打赏
  • 举报
回复
你都能想到要截取前10个字再加“…”了,你还不知道怎么做啊.

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧