Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8129193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:12:30+00:00 2026-06-06T08:12:30+00:00

I have e.g. string str =’Àpple’; string strNew=; char[] A = {‘À’,’Á’,’Â’,’Ä’}; char[] a

  • 0

I have e.g.

string str ='Àpple';
string strNew="";
char[] A = {'À','Á','Â','Ä'};
char[] a = {'à','á','â','ä'};

I want to look through the str and see if found replace with Ascii code ‘A’ . So the result should be:

strNew = 'Apple';

Here is my code:

for (int i = 0; i < str.Length; i++)
{ 
    if(str[i].CompareTo(A))
       strNew += 'A'
    else if(str[i].CompareTo(a)) 
       strNew +='a'
    else
       strNew += str[i];
}

But the compare function doesn’t work, so what other function I can use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:12:32+00:00Added an answer on June 6, 2026 at 8:12 am

    It sounds like you could just use:

    if (A.Contains(str[i]))
    

    but there are certainly more efficient ways of doing this. In particular, avoid string concatenation in a loop.

    My guess is that there are Unicode normalization approaches which don’t require you to hard-code all this data, too. I’m sure I remember one somewhere, around encoding fallbacks, but I can’t put my finger on it… EDIT: I suspect it’s around String.Normalize – worth a look, at least.

    At the very least, this would be more efficient:

    char[] mutated = new char[str.Length];
    for (int i = 0; i < str.Length; i++)
    {
        // You could use a local variable to avoid calling the indexer three
        // times if you really want...
        mutated[i] = A.Contains(str[i]) ? 'A'
                   : a.Contains(str[i]) ? 'a'
                   : str[i];
    }
    string strNew = new string(mutated);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like: string str = https://abce/MyTest; I want to check if
Suppose I have a string char* str . I print it to the buffer
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
I have a string like this String str = la$le\\$li$lo . I want to
I have a string str a\tb\tc\td\te I want the 1st field value a to
I have string array str[10][3] , it is full of values. Now I want
Given a string *Str of ASCII characters, write the pseudo code to remove the
Have String str May 23 2011 12:20:00, want to convert it to date such
I have following string String str = replace :) :) with some other string;
So, suppose I have a string str = MyClass, now I want to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.