Assuming the column bodycontains a row, you can truncate it like this:
var body = (String) reader["body"];
var truncatedBody = body.Substring(0, Math.Min(body.Length, 20));
If the column can be null, you will need to check it before calling Substring.
Substring , . .
, :
public static class StringExtensions {
public static String Truncate(this String str, Int32 length) {
if (length < 0)
throw new ArgumentOutOfRangeException("length");
if (str == null)
return String.Empty;
return str.Substring(0, Math.Min(str.Length, length));
}
}
:
((String) reader["body"]).Truncate(20)