Reputation: 6306
I have a substring which is defined as:
<p>@Html.Raw(item.Post.Substring(0, 300))...</p>
The text I'm entering far exceeds 300 characters, but I'm still getting the error above. I thought the second param on the substring method was supposed to be the number of characters you want to cut to?
Unless I'm wrong and I'm missing something?
Upvotes: 1
Views: 352
Reputation: 8308
Try following
item.Post.Substring(0, Math.Min(300, item.Post.Length));
Upvotes: 1