Skip to content

Instantly share code, notes, and snippets.

@wbeckley
Created April 26, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbeckley/1f44cad11ea19b6d6e6460dc6cec9fd1 to your computer and use it in GitHub Desktop.
Save wbeckley/1f44cad11ea19b6d6e6460dc6cec9fd1 to your computer and use it in GitHub Desktop.
[2017-04-24] Challenge #312 [Easy] L33tspeak Translator [Solution]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace DailyProgrammerEasy
{
class Code
{
//[2017-04-24] Challenge #312 [Easy] L33tspeak Translator
public string ConvertText(string textToConvert)
{
string result = textToConvert;
bool leet = false;
Dictionary<string, string> leetDictionary = new Dictionary<string, string>() { { "A", "4" }, { "B", "6" }, { "E", "3" }, { "I", "1" }, { "L", "1" }, { "M", "(V)" }, { "N", "(\\)" }, { "O", "0" }, { "S", "5" }, { "T", "7" }, { "V", "\\/" }, { "W", "`//" } };
foreach (KeyValuePair<string, string> item in leetDictionary)
{
if (result.Contains(item.Value))
{
leet = true;
break;
}
}
if (!leet)
{
foreach (KeyValuePair<string, string> letter in leetDictionary)
{
result = Regex.Replace(result, letter.Key, letter.Value, RegexOptions.IgnoreCase);
}
}
else
{
foreach (KeyValuePair<string, string> letter in leetDictionary)
{
result = Regex.Replace(result, Regex.Escape(letter.Value), letter.Key, RegexOptions.IgnoreCase);
}
result = char.ToUpper(result[0]) + result.Substring(1).ToLower();
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment