S
shapper
Hello,
I am using a method to truncate a string without breaking words and
when the string is truncated ellipses (...) should be added.
With:
Truncate(true, 108, "Article Long Title - The development of an
ASP.NET MVC RC2 with an SQL Database and C# ")
I get the error:
Index and length must refer to a location within the string.
Parameter name: length
public static String Truncate(Boolean ellipsis, Int32 length,
String text) {
String trimmed = text.Substring(0,
length);
if (text.Length <= length || length == 0 || text[length -
1].Equals(' '))
return trimmed;
Int32 i = length;
while (i > 0 && !trimmed[i - 1].Equals(' ')) i--;
return ellipsis ? String.Concat(trimmed.Substring(0, i), " ...
") : trimmed.Substring(0, i);
} // Truncate
What am I missing?
Thanks,
Miguel
I am using a method to truncate a string without breaking words and
when the string is truncated ellipses (...) should be added.
With:
Truncate(true, 108, "Article Long Title - The development of an
ASP.NET MVC RC2 with an SQL Database and C# ")
I get the error:
Index and length must refer to a location within the string.
Parameter name: length
public static String Truncate(Boolean ellipsis, Int32 length,
String text) {
String trimmed = text.Substring(0,
length);
if (text.Length <= length || length == 0 || text[length -
1].Equals(' '))
return trimmed;
Int32 i = length;
while (i > 0 && !trimmed[i - 1].Equals(' ')) i--;
return ellipsis ? String.Concat(trimmed.Substring(0, i), " ...
") : trimmed.Substring(0, i);
} // Truncate
What am I missing?
Thanks,
Miguel