using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FuzzyString { public static partial class Operations { public static string Capitalize(this string source) { return source.ToUpper(); } public static string[] SplitIntoIndividualElements(string source) { string[] stringCollection = new string[source.Length]; for (int i = 0; i < stringCollection.Length; i++) { stringCollection[i] = source[i].ToString(); } return stringCollection; } public static string MergeIndividualElementsIntoString(IEnumerable source) { string returnString = ""; for (int i = 0; i < source.Count(); i++) { returnString += source.ElementAt(i); } return returnString; } public static List ListPrefixes(this string source) { List prefixes = new List(); for (int i = 0; i < source.Length; i++) { prefixes.Add(source.Substring(0, i)); } return prefixes; } public static List ListBiGrams(this string source) { return ListNGrams(source, 2); } public static List ListTriGrams(this string source) { return ListNGrams(source, 3); } public static List ListNGrams(this string source, int n) { List nGrams = new List(); if (n > source.Length) { return null; } else if (n == source.Length) { nGrams.Add(source); return nGrams; } else { for (int i = 0; i < source.Length - n; i++) { nGrams.Add(source.Substring(i, n)); } return nGrams; } } } }