I have a hyperlink with the navigate property set like this:
NavigateUrl='<%# Eval("My Text") %>'
How can I limit the string to 140 characters ? I have tried this Eval("My Text").ToString().Substring(0,140) but if the string length is less than 140 characters it throws an exception.
And yet an other possibility:
Eval("My Text").ToString().PadRight(140).Substring(0,140).TrimEnd()
Edit:
I do like LINQ, too:
Eval("My Text").ToString().Take(140).Aggregate("", (x,y) => x + y)
Use It (:
< % # Eval("MyText").ToString().Length <= 30 ? Eval("MyText") : Eval("MyText").ToString().Substring(0, 30)+"..." % >
Damn I like LINQ:
string.Concat('<%# Eval("My Text") %>'.ToString().Where((char, index) => index < 140))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With