如何仅从左侧获取20个字符 [英] How to get only 20 characters from left side
本文介绍了如何仅从左侧获取20个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的sql命令
Here is my sql command
select top 10 * from comment inner join list on list.id=comment.id where status=1 order by comment_time desc
我想这样创建
I want to create like this
string str=comments.aspx?id="+dr["id"]+">"+dr["comment_body"]
在注释正文中,我只需要20个字符.
请任何人可以帮助我.
在此先感谢
我使用了上述解决方案,但显示了类似
的错误
In the comment body i need only 20 characters.
Please any one can help me.
Thanks in advance
i used the above solution but it shown error like
Index and length must refer to a location within the string.
Parameter name: length
我将数据类型用作ntext
i am using data type as ntext
推荐答案
这可以在2个地方完成
1.在查询中-如果您没有其他使用完整评论的地方,更好的地方
使用子字符串功能,请参阅
SUBSTRING(Transact-SQL) [ String.Substring方法(Int32,Int32) [
This can be done in 2 places
1. in the query - better place if you have no other use of the full comment
using substring function, refer to
SUBSTRING (Transact-SQL)[^]
2. in c#
using String.Substring method, refer to
String.Substring Method (Int32, Int32)[^]
尝试一下.
Try this.
string str=comments.aspx?id="+dr["id"]+">"+dr["comment_body"].Substring(0, 20);
string str=comments.aspx?id="+dr["id"]+">"+Convert.ToString(dr["comment_body"]).SubString(0,20);
这篇关于如何仅从左侧获取20个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文