chrtran("AB", "AB", "BC") yields "CC"(2) the code in the toolkit was written well before Generics were introduced
Console.WriteLine(" {0} ", "AB".ChrTran("AB", "BC"));
// string namespace GregoryAdam.Base.ExtensionMethods { public static partial class ExtensionMethods { public static string ChrTran(this string s, string from, string to) { var sb = new StringBuilder(s, s.Length); int i, j; for( i = -1; ++i < sb.Length; ) { if ((j = from.IndexOf(sb[i])) >= 0) { if (j < to.Length) { sb[i] = to[j]; } else { sb.Remove(i--, 1); } } } return sb.ToString(); } } }Below
// Generic namespace GregoryAdam.Base.ExtensionMethods { public static partial class ExtensionMethods { #region InList public static bool InList<T>(this T s, params T[] list) where T : IEquatable«T» { return list.Contains(s); } #endregion //-------------------------------------------------------------------------------- #region Between public static bool Between<T>(this T s, T s1, T s2) where T : IComparable«T» { return (s.CompareTo(s1) >= 0) && (s.CompareTo(s2) <= 0); } #if false // 3 times slower public static bool Between(this IComparable s, IComparable s1, IComparable s2) { return (s.CompareTo(s1) >= 0) && (s.CompareTo(s2) <= 0); } #endif #endregion //-------------------------------------------------------------------------------- } }