Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string input = TextBox1.Text;
Dictionary<string, string> map = new Dictionary<string, string>();
map.Add("go", "GYO");
map.Add("GO", "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.Compiled);


Hello To All,

Why my case sensitive not working I am not getting any idea. Does anybody have any idea?

What I have tried:

Tried all RegexOptions
Not worked :(

Thanks in advance.
Posted
Updated 2-May-21 4:02am
Comments
Richard MacCutchan 2-May-21 7:12am    
You have not told us what the problem is. And please, do not just say, "not working", as we have no idea what that means.
Member 13003138 2-May-21 11:12am    
Sorry for my poor English. The issue is come to all results same for-
go, Go and GO= GYO (Same results come)

But I have mapped for different words. I means for 'go' the output is GYO for 'GO' the output is OMO and finally for the Go the output will be OIO. But not works like that.
Richard MacCutchan 2-May-21 11:31am    
The Dictionary class allows you to select entries by the key value. There is no need for this complicated RE code.

1 solution

"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.

In this case, it probably "doesn't work" because you are doing it in a loop, and throwing away all previous results each time you go round it ... there is no way to exit the foreach loop when you find a match, so it works, then it gives you the result of the enext one, and so on.
 
Share this answer
 
Comments
Member 13003138 2-May-21 11:12am    
Sorry for my poor English. The issue is come to all results same for-
go, Go and GO= GYO (Same results come)

But I have mapped for different words. I means for 'go' the output is GYO for 'GO' the output is OMO and finally for the Go the output will be OIO. But not works like that.
OriginalGriff 2-May-21 11:27am    
Yes. Because you are doing it in a loop so you always get the result for the last time you went round it ...

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