string input = TextBox1.Text; Dictionary<string, string> map = new Dictionary<string, string>(); map.Add("go", "GYO"); map.Add("oo", "OMO"); map.Add("Go", "OIO"); string temp = input; foreach (var entry in map) { string key = entry.Key; string value = entry.Value; temp = Regex.Replace(temp, key, match => { bool isUpper = char.IsUpper(match.Value[0]); char[] result = value.ToCharArray(); result[0] = isUpper ? char.ToUpper(result[0]) : char.ToLower(result[0]); return new string(result); }, RegexOptions.IgnoreCase);
Dictionary<string, string> map = new Dictionary<string, string>(); map.Add("go", "GYO"); map.Add("oo", "OMO"); map.Add("Go", "OIO"); // usage string mapItem; if(map.TryGetValue(TextBox1.Text, out mapItem)) { // handle the valid map entry now in 'mapItem } else { // handle invalid data in TextBox }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)