Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Allows an update to a window's title with added a new value while maintaining the base title.
- /// 'Notepad'
- /// </summary>
- /// <remarks>
- /// Example:
- /// string result = SetTitleValue("Notepad","Document1");
- /// MessageBox.Show(result);
- /// // result = 'Notepad - Document1'
- /// result = SetTitleValue("Notepad",null); // or string.Empty
- /// // result = 'Notepad';
- /// </remarks>
- /// <param name="titleBase">The base start of the title</param>
- /// <param name="value">The value appended onto the <see cref="titleBase"/></param>
- /// <returns>
- /// The formated title as "{0}{1}{2}", where
- /// {0} is <see cref="titleBase"/>,
- /// {1} is <see cref="separator"/>, and
- /// {2} is <see cref="value"/>
- /// </returns>
- public static string SetTitleValue(string titleBase, string value,string separator = " - ") {
- string s = value;
- if(string.IsNullOrWhiteSpace(s))
- s = string.Empty;
- string title = s
- .Trim()
- .TrimEnd(separator.ToCharArray());
- if(title.Equals(titleBase,StringComparison.InvariantCultureIgnoreCase)) {
- title = string.Empty;
- }
- if(string.IsNullOrWhiteSpace(title))
- separator = string.Empty;
- return string.Format("{0}{1}{2}",titleBase,separator,title);
- }
Advertisement
Add Comment
Please, Sign In to add comment