using System;using System.Collections.Generic;
public static class Program
public static bool isUnicodeApostrophe(this char c)
if (c == '\'' || c == '\u2019') return true;
public static int CountWordsforCode(this string s)
if (string.IsNullOrEmpty(s)) return 0;
if (char.IsLetterOrDigit(s[0])) { wc = 1; }
for (int i = 1; i < s.Length; i++)
if (i < s.Length - 1 && char.IsLetter(s[i - 1]) && s[i].isUnicodeApostrophe() && char.IsLetter(s[i + 1])) {
if (i < s.Length - 1 && char.IsNumber(s[i - 1]) && (s[i] == ',') && char.IsNumber(s[i + 1]))
if (i < s.Length - 1 && char.IsNumber(s[i - 1]) && (s[i] == '.') && char.IsNumber(s[i + 1]))
if (char.IsWhiteSpace(s[i - 1]) || char.IsPunctuation(s[i - 1]) || char.IsSymbol(s[i - 1]))
if (char.IsLetterOrDigit(s[i]))
return wc - (apc * 2) + apc - (tc * 2) + tc - (dc * 2) + dc;
public static void Main()
Dictionary<string, bool> CSharpOperands = new Dictionary<string, bool>()
string[] tokens = { "e", "ab", "abc", "abcdef", "", "a,b", "e e a e", "e}}}}}})*",
"(CAN'T, DON'T)", "{'val1','val2'}", "\"what's here\"",
"\"1'1 2 3 what's he’s isn't\"", "for goodness’ sake",
"'em exuse me", "\"what 'dillygrout' is?\"", "\"word-for-word\"",
"newToolStripMenuItem_Click(object sender, EventArgs e)",
"(tabControl1.TabCount + 1).ToString();",
"http://en.wikipedia.org/wiki/Rice's_theorem",
"<script type=\"text/javascript\">" };
foreach (var token in tokens)
Console.WriteLine(token + "\nword count = " + token.CountWordsforCode() + "\n");