176
Views
5
Comments
Action Replace
Question
Hello everyone!
I want make a action than read one text with 160 characters and replace the letters with accents by letters without accents.
Example: Replace(message,","e"), Replace(message,","a").

Best Regards, Paulo Torres

2020-12-07 17-35-54
António Chinita
Hi Paulo, you gave the answer yourself :)
The easiest way to do it is with the replace() function.

Replace(Replace(Replace(Replace(Replace(message,"á","a"),"à","a"),"ã","a),"â","a",)"é","e") (... and so on)

If you feel 1337 today and would like to do this dinamically... You can always build an extension.

static string RemoveDiacritics(string stIn) {
  string stFormD = stIn.Normalize(NormalizationForm.FormD);
  StringBuilder sb = new StringBuilder();

  for(int ich = 0; ich < stFormD.Length; ich++) {
    UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
    if(uc != UnicodeCategory.NonSpacingMark) {
      sb.Append(stFormD[ich]);
    }
  }

  return(sb.ToString().Normalize(NormalizationForm.FormC));
}
Source: stackoverflow

:)
2016-04-21 20-09-55
J.
 
MVP
Or toy with regex perhaps
2023-08-28 07-00-10
Paulo Torres
Champion
Thank you very much António and others guys :)
I was doing with function regex_replace but this function replaced lowercase letters to uppercase... Not serve for me!
I don't know how maked many replaceds in one expression and is easy :)

Thanks =)
2011-10-11 00-46-16
Diogo Cordeiro
Don't think I went this 1337 - https://en.wikipedia.org/wiki/Leet - but, definitely went somewhere.

XIF .Net Version of the code referenced by @António Chinita here
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.