So here’s the code for once and always
. Using the Sitecore framework as much as possible:
1 private static string GetNiceShortIntro(int maxLength, bool stripHtml, bool htmlEncode, params string[] fieldValues)
2 {
3 string intro = StringUtil.GetString(fieldValues);
4
5 if(stripHtml)
6 {
7 intro = StringUtil.RemoveTags(intro);
8 }
9
10 if(maxLength > 0 && intro.Length > maxLength)
11 {
12 intro = intro.Substring(0, maxLength);
13 }
14
15 if(htmlEncode)
16 {
17 intro = HttpUtility.HtmlEncode(intro);
18 }
19
20 return intro;
21 }
