Note that there are some explanatory texts on larger screens.

plurals
  1. POLow complexity algorithm to remove/replace special characters
    primarykey
    data
    text
    <p>I want to replace some invalid characters in the name of a file uploaded to my application.</p> <p>I've searched up to something on the internet and found some complex algorithms to do it, here's one:</p> <pre><code> public static string RemoverAcentuacao(string palavra) { string palavraSemAcento = null; string caracterComAcento = "áàãâäéèêëíìîïóòõôöúùûüçáàãâÄéèêëíìîïóòõÖôúùûÜç, ?&amp;:/!;ºª%‘’()\"”“"; string caracterSemAcento = "aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC___________________"; if (!String.IsNullOrEmpty(palavra)) { for (int i = 0; i &lt; palavra.Length; i++) { if (caracterComAcento.IndexOf(Convert.ToChar(palavra.Substring(i, 1))) &gt;= 0) { int car = caracterComAcento.IndexOf(Convert.ToChar(palavra.Substring(i, 1))); palavraSemAcento += caracterSemAcento.Substring(car, 1); } else { palavraSemAcento += palavra.Substring(i, 1); } } string[] cEspeciais = { "#39", "---", "--", "'", "#", "\r\n", "\n", "\r" }; for (int q = 0; q &lt; cEspeciais.Length; q++) { palavraSemAcento = palavraSemAcento.Replace(cEspeciais[q], "-"); } for (int x = (cEspeciais.Length - 1); x &gt; -1; x--) { palavraSemAcento = palavraSemAcento.Replace(cEspeciais[x], "-"); } palavraSemAcento = palavraSemAcento.Replace("+", "-").Replace(Environment.NewLine, "").TrimStart('-').TrimEnd('-').Replace("&lt;i&gt;", "-").Replace("&lt;-i&gt;", "-").Replace("&lt;br&gt;", "").Replace("--", "-"); } else { palavraSemAcento = "indefinido"; } return palavraSemAcento.ToLower(); } </code></pre> <p><strong>There's a way to do it with a less complex algorithm?</strong> </p> <p>I think this algorithm is very complex to something not too complex, but I can't think in something diferent of this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload