/// <summary> /// Truncates this Title so it has a maximum number of words. Spaces are used to determine words, thus two /// spaces in a Title will cause two words to be mistakenly identified /// </summary> /// <param name="noWords">the number of words to show</param> /// <returns> /// a reference to the called object (itself) /// </returns> public TitleBuilder Truncate(int noWords) { if (noWords < 1) { throw new ArgumentException("Truncation must be to one or more words"); } string[] words = Title.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (noWords >= words.Length) { return(this); } Title = new StringBuilder(); for (int i = 0; i < noWords; i++) { Title.Append(words[i]).Append(" "); } Title.Append("..."); return(this); }
/// <summary> /// Returns a string that represents the value of this obj /// </summary> public override string ToString() { return(Title.ToString()); }