101
Script / Title Case
« on: July 05, 2018, 20:24:16 »
I saw this the other day
I thought I'd like to translate it to MS & add it to a button.
I can grab & split a filename, I can see how I could use the str selection to alter the words I want in lower case to lower case ... but I'm wondering if I need something like a regex version of
Maybe I just haven't figured out the ordering of commands to modify the arrays yet but I'd really like something that would give me a [a-z] -> [A-Z] function
Any advice Mathias?
Code: [Select]
using System;
using System.Collections.Generic;
public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
//Words that will not be capitalized; add words to this list as required
string[] exceptionsArray = { "a", "an", "and", "any", "at", "from", "into", "of", "on", "or", "the", "to", };
List<string> exceptions = new List<string>(exceptionsArray);
//Break the input text into a list of capitalized (not upper case) words
text = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(text.ToLower());
List<string> words = new List<string>(text.Split(new char[] { ' ' }));
//Always leave the first word capitalized, regardless of what it is
text = words[0];
words.RemoveAt(0);
//Check each remaining word against the list, and append it to the new text
foreach (string s in words)
{
if (exceptions.Contains(s.ToLower()))
text += " " + s.ToLower();
else
text += " " + s;
}
return text;
}
}
I thought I'd like to translate it to MS & add it to a button.
I can grab & split a filename, I can see how I could use the str selection to alter the words I want in lower case to lower case ... but I'm wondering if I need something like a regex version of
Code: [Select]
<str> StrReplace(<str> input, <str> find, <str> with );
Maybe I just haven't figured out the ordering of commands to modify the arrays yet but I'd really like something that would give me a [a-z] -> [A-Z] function
Any advice Mathias?