Processing Ajax...







Are you sure you want to delete this item?


Are you sure you want to delete this item?

Convert to Title Case (Smart Extended)

This macro will convert the selected text to title case, and has a hard coded list of exceptions as well.
Minimum Version
Created By
Thomas Malloch (BFS)
Date Created
Mar 10, 2020
Date Last Modified
Mar 10, 2020

Macro Code

using System;
using System.Text;
using System.Collections.Generic;

public static class ClipboardFusionHelper
	private static readonly string[] ExceptionsArray =
		//                                                              Articles                                                   //

		//                                                              Coordinating conjunctions		                           //	

		//                                                              Postpositions                                              //
		"aslant", //(archaic)
		"notwithstanding", //(also prepositional)
		"short", //(also prepositional)

		//                                                             Single Word Prepositions                                   //
		"absent", //(law)
		"cross", //(archaic)


		// (poetic or archaic) 

		// (archaic)
		"'long", //(abbreviation), 
		"alongst", //(archaic)

		//(poetic or archaic)
		"amongst", //(in US English poetic or archaic)
		"apropos", //(rare for apropos of)
		"apud", //(formal)

		"@", //(abbreviation)

		//(dialectal or archaic)
		"ahind", //(dialectal or archaic)
		"'neath", //(poetic)
		"neath", //(poetic)
		"atween", //(dialectal or archaic)
		"ayond", //(dialectal or archaic)
		"chez", //(rare)


		"c. ",
		"dehors", //(law)
		"spite", //(abbreviation)
		"nearer", //(comparative), 
		"nearest", //(superlative)
		"anear", //(archaic)
		"notwithstanding", //(also postpositional)
		"o'", //(poetic or eye-dialect)
		"outen", //(archaic or dialectal)
		"o'er", //(poetic)
		"pace", //(formal)
		"post", //(often hyphenated)
		"pre", //(often hyphenated)
		"pro", //(often hyphenated)
		"qua", //(formal)
		"re", //(often used with colon)
		"sans", //(formal)
		"sauf", //(archaic)
		"sithence", //(archaic)
		"thru", //(abbreviation)
		"thruout", //(abbreviation)



		"vice", //(formal)
		"vis-à-vis", //(formal)

		"w/i", //(abbreviation)
		"w/o", //(abbreviation)

	private static string[] MultiWordExceptionArray = 
		//                                                               Two-word Prepositions                                          //
		"according to",
		"across from",
		"adjacent to",
		"ahead of",
		"along with",
		"apart from",
		"as for",
		"as of",
		"as per",
		"as regards",
		"aside from",
		"back to",
		"because of",
		"close to",
		"counter to",
		"down on",
		"due to",
		"except for",
		"far from",
		"inside of",
		"instead of",
		"left of",
		"near to",
		"next to",
		"opposite of",
		"opposite to",
		"other than",
		"out from",
		"out of",
		"outside of",
		"owing to",
		"prior to",
		"pursuant to",
		"rather than",
		"regardless of",
		"right of",
		"subsequent to",
		"such as",
		"thanks to",
		"up to",

		//                                                                      Three-word Prepositions                             //       
		"as far as", //is one example of the many expressions which can be analyzed as as+adjective+as rather than a multiword preposition
		"as opposed to",
		"as soon as",
		"as well as",

		//                                                                       Preposition + (article) + noun + preposition               //
		//English has many idiomatic expressions that act as prepositions that can be analyzed as a preposition followed by a noun (sometimes preceded by the definite or, occasionally, indefinite article) followed by another preposition.
		"at the behest of",
		"by means of",
		"by virtue of",
		"for the sake of",
		"for lack of",
		"for want of",
		"in accordance with",
		"in addition to",
		"in case of",
		"in front of",
		"in lieu of",
		"in place of",
		"in point of",
		"in spite of",
		"on account of",
		"on behalf of",
		"on top of",
		"with regard to", //(sometimes written as "w/r/t")
		"with respect to",
		"with a view to",

	private static readonly string[] CaseSensitiveExceptionArray = 
		//                                                             OTHERS                                                   //

	private static readonly HashSet<string> Exceptions = new HashSet<string>(ExceptionsArray);
	private static Dictionary<string, string> MultiWordExceptions;
	private static Dictionary<string, string> CaseSensitiveExceptions;

	public static string ProcessText(string text)
        return null;

	private static string ToTitleCaseSmart(string text)
		// build multi-word exception dictionary
		MultiWordExceptions = new Dictionary<string, string>();
		foreach (string exception in MultiWordExceptionArray)
			string key = "_" + exception.GetHashCode().ToString() + "_";
			if (!MultiWordExceptions.ContainsKey(key))
				MultiWordExceptions.Add(key, exception);

			// replace exceptions with something we can easily look for and replace later
			while (true)
				int index = text.IndexOf(exception, StringComparison.OrdinalIgnoreCase);
				if (index == -1)

				string modified = text.Substring(0, index);
				modified += key;
				modified += text.Substring(index + exception.Length);
				text = modified;

		// build case sensitive exceptions
		CaseSensitiveExceptions = new Dictionary<string, string>();
		foreach (string exception in CaseSensitiveExceptionArray)
			string key = "_" + exception.GetHashCode().ToString() + "_";
			if (!CaseSensitiveExceptions.ContainsKey(key))
				CaseSensitiveExceptions.Add(key, exception);

			// replace exceptions with something we can easily look for and replace later
			text = text.Replace(exception, key);

		// do the normal title case processing
		Queue<string> words = new Queue<string>(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(text.ToLowerInvariant()).Split(new char[] {' '}));
		StringBuilder builder = new StringBuilder(words.Dequeue());
		while (words.Count > 0)
			string word = words.Dequeue();
			string lower = word.ToLower();
			builder.Append(" ");
			if (Exceptions.Contains(lower))

		// go through and replace our other exceptions with the proper values
		text = builder.ToString();
		foreach (string key in MultiWordExceptions.Keys)
			text = text.Replace(key, MultiWordExceptions[key]);
		foreach (string key in CaseSensitiveExceptions.Keys)
			text = text.Replace(key, CaseSensitiveExceptions[key]);

		// return the result
		return text;