This project has moved and is read-only. For the latest updates, please go here.

Example project for replacing a list of words, part II

Dec 30, 2013 at 11:56 PM
Edited Dec 31, 2013 at 12:02 AM
// continued from "Example project for replacing a list of words, part I"
        ExpandWordPairs("judgement", "judgment");
        ExpandWordPairs("kerb", "curb");
        ExpandWordPairs("kerbing", "curbing");
        ExpandWordPairs("kilometre", "kilometer");
        ExpandWordPairs("labour", "labor");
        ExpandWordPairs("labouring", "laboring");
        ExpandWordPairs("leapt", "leaped");
        ExpandWordPairs("learnt", "learned");
        ExpandWordPairs("leukæmia", "leukemia");
        ExpandWordPairs("licence", "license");
        ExpandWordPairs("liquorice", "licorice");
        ExpandWordPairs("litre", "liter");
        ExpandWordPairs("manœuvre", "maneuver");
        ExpandWordPairs("manœuvring", "maneuvering");
        ExpandWordPairs("marvellous", "marvelous");
        ExpandWordPairs("mediæval", "medieval");
        ExpandWordPairs("metre", "meter");
        ExpandWordPairs("modelling", "modeling");
        ExpandWordPairs("mould", "mold");
        ExpandWordPairs("mollusc", "mollusk");
        ExpandWordPairs("moult", "molt");
        ExpandWordPairs("mum", "mom");
        ExpandWordPairs("monologue", "monolog");
        ExpandWordPairs("moustache", "mustache");
        ExpandWordPairs("moisturiser", "moisturizer");
        ExpandWordPairs("moisturising", "moisturizing");
        ExpandWordPairs("neighbour", "neighbor");
        ExpandWordPairs("neighbourly", "neighborly");
        ExpandWordPairs("œnology", "enology");
        ExpandWordPairs("œsophagus", "esophagus");
        ExpandWordPairs("œstrogen", "estrogen");
        ExpandWordPairs("odour", "odor");
        ExpandWordPairs("offence", "offense");
        ExpandWordPairs("omelette", "omelet");
        ExpandWordPairs("organisation", "organization");
        ExpandWordPairs("organise", "organize");
        ExpandWordPairs("organising", "organizing");
        ExpandWordPairs("orthologue", "ortholog");
        ExpandWordPairs("orthopædic", "orthopedic");
        ExpandWordPairs("pædiatric", "pediatric");
        ExpandWordPairs("pædophile", "pedophile");
        ExpandWordPairs("pyjamas", "pajamas");
        ExpandWordPairs("paralyse", "paralyze");
        ExpandWordPairs("paralysed", "paralyzed");
        ExpandWordPairs("paralysing", "paralyzing");
        ExpandWordPairs("paralysation", "paralyzation");
        ExpandWordPairs("parlour", "parlor");
        ExpandWordPairs("pedagogue", "pedagog");
        ExpandWordPairs("plough", "plow");
        ExpandWordPairs("ploughed", "plowed");
        ExpandWordPairs("ploughing", "plowing");
        ExpandWordPairs("practise", "practice");
        ExpandWordPairs("practised", "practiced");
        ExpandWordPairs("practising", "practicing");
        ExpandWordPairs("pretence", "pretense");
        ExpandWordPairs("prise", "prize");
        ExpandWordPairs("programme", "program");
        ExpandWordPairs("quarrelled", "quarreled");
        ExpandWordPairs("quarrelling", "quarreling");
        ExpandWordPairs("realise", "realize");
        ExpandWordPairs("realising", "realizing");
        ExpandWordPairs("realisation", "realization");
        ExpandWordPairs("rigour", "rigor");
        ExpandWordPairs("routeing", "routing");
        ExpandWordPairs("savior", "saviour");
        ExpandWordPairs("savory", "savoury");
        ExpandWordPairs("sceptic", "skeptic");
        ExpandWordPairs("scrutinise", "scrutinize");
        ExpandWordPairs("shew", "show");
        ExpandWordPairs("shewing", "showing");
        ExpandWordPairs("signalling", "signaling");
        ExpandWordPairs("skilful", "skillful");
        ExpandWordPairs("speciality", "specialty");
        ExpandWordPairs("spelt", "spelled");
        ExpandWordPairs("spoilt", "spoiled");
        ExpandWordPairs("storey", "story");
        ExpandWordPairs("sulphur", "sulfur");
        ExpandWordPairs("theatre", "theater");
        ExpandWordPairs("tyre", "tire");
        ExpandWordPairs("tranquillity", "tranquility");
        ExpandWordPairs("travelled", "traveled");
        ExpandWordPairs("traveller", "traveler");
        ExpandWordPairs("travelling", "traveling");
        ExpandWordPairs("tumour", "tumor");
        ExpandWordPairs("urbanisation", "urbanization");
        ExpandWordPairs("valour", "valor");
        ExpandWordPairs("vice", "vise");
        ExpandWordPairs("victual", "vittle");
        ExpandWordPairs("vigour", "vigor");
        ExpandWordPairs("vigourous", "vigorous");
        ExpandWordPairs("vigourously", "vigorously");
        ExpandWordPairs("whiskey", "whisky");
        ExpandWordPairs("woolen", "woollen");
        ExpandWordPairs("yoghurt", "yogurt");
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Cursor.Current = Cursors.WaitCursor;
        try
        {
            string filename = string.Empty;
            string britSpelling = string.Empty;
            string amiSpelling = string.Empty;
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                filename = openFileDialog1.FileName;
            }
            else
            {
                MessageBox.Show("No file selected - sayonara!");
                return;
            }
            using (DocX document = DocX.Load(filename))
            {
                foreach (string s in wordPairs)
                {
                    britSpelling = GetFirstHalf(s);
                    amiSpelling = GetSecondHalf(s);
                    document.ReplaceText(britSpelling, amiSpelling);
                }
                document.Save();
            }
        }
        finally
        {
            Cursor.Current = Cursors.Default;
        }
        MessageBox.Show("Done!");
    }

    private string GetSecondHalf(string s)
    {
        return s.Split('#').Last();
    }

    private string GetFirstHalf(string s)
    {
        return s.Split('#').First();
    }
}
}