索引和长度必须引用在字符串中的位置? [英] Index and length must refer to a location within the string?

查看:274
本文介绍了索引和长度必须引用在字符串中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拿到第50个字母,所以我用了的子函数来得到它。

I am trying to get the first 50 letters, so I used the subString function to get it.

正如你所看到的,我用这个code获得它:

As you can see, I used this code to get it:

<%# Eval("BannerDescription").ToString.Substring(1, 50)%>

不过遗憾的是它不工作和错误消息来了:

But unfortunately it's not working and an error message is coming up:

索引和长度必须引用的位置在字符串中。

Index and length must refer to a location within the string.

那么,有没有解决任何其他的方式?

So is there any other way to fix it?

,因为用户是一个谁正在控制数据输入!有的时候,他该怎么输入10个字母其他时候,也许1000的信让我怎么能解决这个?

because the user is the one who is controlling the data entry! some times he gonna enter 10 letters other times maybe 1000 letter so how can i solve this ?

我想他们所有,但我们可以用这种方式:

I tried them all but can we use it this way :

&LT;%#IIF(EVAL(BannerDescription)的ToString()长度和GT; 49,评估和演示(BannerDescription)的ToString()子串(0,49),评估和演示(BannerDescription))%&GT;

感谢。

推荐答案

也许是这样的 -

<%# Eval("BannerDescription").ToString().Substring(0, Math.Min(Eval("BannerDescription").ToString().Length, 50)) %>

这篇关于索引和长度必须引用在字符串中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆