public static void Main()
ShowAlternatives("+448700610100");
ShowAlternatives("08700610100");
private static void ShowAlternatives(string number)
Console.WriteLine("Alternatives for {0}:", number);
foreach (var alternative in GenerateAlternativeNumbers(number))
Console.WriteLine(" {0}", alternative);
private static string[] GenerateAlternativeNumbers(string matchAgainst)
matchAgainst = matchAgainst.Replace(" ", string.Empty);
if (matchAgainst.StartsWith("+44"))
matchAgainst = matchAgainst.Replace("+44", "0");
matchAgainst.Insert(5, " "), matchAgainst.Insert(4, " "), matchAgainst.Insert(4, " ").Insert(8, " "), matchAgainst.ReplaceFirst("0", "+44"), matchAgainst.ReplaceFirst("0", "+44").Insert(6, " "), matchAgainst.ReplaceFirst("0", "+44").Insert(5, " ").Insert(9, " ")}
static class StringReplace
public static string ReplaceFirst(this string str, string initial, string replace)
if (!str.Contains(initial))
int index = str.IndexOf(initial);
if (initial.Length != replace.Length)
bool initOrReplace = initial.Length < replace.Length;
int diff = initOrReplace ? replace.Length - initial.Length : initial.Length - replace.Length;
str = initOrReplace ? str.Insert(index, " ") : str.Remove(index, 1);
char[] buffer = new char[str.Length];
str.CopyTo(0, buffer, 0, str.Length);
for (int i = index; i < index + replace.Length; i++)
StringBuilder sb = new StringBuilder();