Gabriëlle
-
2/11/2009 2:28:51 PM
RE:LimitLength transformation
Hi Ondrej,
OK thank you, I've searched the entire internet and finally found a solution. For other users:
Make a new function called TrimWords.cs
Enter this code:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using CMS.GlobalHelper; using CMS.FileManager; using CMS.CMSHelper;
/// <summary> /// Summary description for TrimWords /// </summary> public static class TrimWords { public static String LimitWords(String Input) { // split input string into words (max 21...last words go in last element) String[] Words = Input.Split(new char[] { ' ' }, 21);
// if we reach maximum words, replace last words with elipse if (Words.Length == 21) Words[20] = "..."; else return Input; // nothing to do
// build new output string String Output = String.Join(" ", Words); return Output; } }
Enter this in your transformation:
<%# TrimWords.LimitWords(Eval("ColumnName").ToString())%>
Et Voila.
|