There may be a more efficient solution, but here's what I came up with:
function ToCase(text, CaseSelection)
return smallcap + text + /smallcap;
var text = hi there CEO of the big corp.;
var Exceptions = [ CEO, CFO, VP, and, the, of, to ];
var result = ToCase(text, CaseSelection);
for (var i in Exceptions)
var re = RegExp(\\b + Exceptions[i] + \\b, gi);
result = result.replace(re, Exceptions[i]);
Note how, if you validate this as written, the word There in the
result is still capitalized, while the word the is not. This is
because I'm using the \b modifier on the regular expression to denote
word boundaries, so that only whole words get replaced.
Also, the whole exceptions thing won't really affect the smallcaps
case. That's really the odd man out here anyway; I would think that you
would probably want to combine title case with smallcaps.
Finally, my usual caveat applies here: Know Thy Data. You can keep
adding exceptions as you discover them, but this is never going to be a
comprehensive solution, because you'll never be able to come up with the
full list of exceptions to title case or proper case logic. The
English language is just too complex for that, and the number of proper
nouns (names) which do not fit the pattern is basically unlimited
(McDonald's, Mies van der Rohe, USA, etc.) There are some kinds of
things that simply can't be reduced to an algorithm.
Users of FusionPro Desktop have unlimited free email support. Contact Printable
Support at [EMAIL PROTECTED]
View FusionPro Knowledge Base, FusionPro Samples at
You are currently subscribed to fusionpro as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Note: All e-mail sent to or from this address will be received or otherwise
recorded by the e-mail recipients of this forum. It is subject to archival,
monitoring or review by, and/or disclosure to someone other than the recipient.