Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
string input = textbox1.Text;
Dictionary<string, string> map = new Dictionary<string, string>();

map.Add("AB", "x");
map.Add("Ab", "z");
map.Add("aB", "p");

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);

}


This is my code...I use this for parse my small words. Like AB=x CB=z etc etc...

But my problem is - it can't understand lowecase and upercase (not case sensative)

Look I mapped :

map.Add("AB", "x");
map.Add("Ab", "z");
map.Add("aB", "p");

I mapped every AB,Ab,aB for different result.

But when i put AB,Ab,aB it just shows "x" !

But i want to show different result for eaches.

Where is my coding problem.

What I have tried:

map.Add("AB", "x");
map.Add("Ab", "z");
map.Add("aB", "p");
Posted
Updated 24-Mar-16 11:24am
Comments
FARONO 24-Mar-16 17:07pm    
RegexOptions.IgnoreCase...?
0HourCoder 24-Mar-16 17:21pm    
yap...great..why it din't get on my eyes !

but all results are in UpperCase...


map.Add("AB", "Z");
map.Add("Ab", "z");
map.Add("aB", "X");
map.Add("xx", "p");

how to define results ! I hope you also give me the best solution !
Sergey Alexandrovich Kryukov 24-Mar-16 19:35pm    
It's apparent that if you did not mention cases at all, all would be case-sensitive. Operations like ToLower and ToUpper are used to ignore the case. So, what exactly do you want to achieve? If you describe that, I think it will make the solution obvious.
—SA
Member 12392870 27-Mar-16 8:40am    
actually your english is high level english...i am not full filled understand. as far i understand you suggested me for mention uper and lower case. but how do i do that? code sample could u give m??
Sergey Alexandrovich Kryukov 27-Mar-16 11:55am    
You need to start with the explanation what exactly do you want to achieve.
—SA

1 solution

You can use something like:
C#
Dictionary<string, string> map = new Dictionary<string, string>( 
                          StringComparer.Ordinal);

See: Dictionary(TKey, TValue) Constructor (IEqualityComparer(TKey)) (System.Collections.Generic)[^]
 
Share this answer
 
Comments
0HourCoder 24-Mar-16 17:34pm    
Hello,
Thank you very much for spend your valuable time give me a solution with link. Ok let me try this.
Hee

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900