TarkaLabs TIL

Tarka Labs is a team of passionate hackers, designers and product managers. We believe in experimental methods to identify the best solutions to problems instead of working on technology du jour. (https://tarkalabs.com/)

Removing Accented (Diacritic) Characters From Strings in Rails

--

If you have a huge list of text records with accented characters and want to get rid of the accented (diacritic) characters because you want to keep the data ASCII-only, Rails offers a simple method to get rid of accented characters without having to go through the pain of writing complex Regex matchers.

I18n.transliterate "São Paulo"=> "Sao Paulo"

As per the official documentation, the `transliterate` method replaces non-ASCII characters with an ASCII approximation.

NOTE: In case, an ASCII Approximation for a non-ASCII character is not found, the character is replaced with a `?`.

--

--

TarkaLabs TIL
TarkaLabs TIL

Published in TarkaLabs TIL

Tarka Labs is a team of passionate hackers, designers and product managers. We believe in experimental methods to identify the best solutions to problems instead of working on technology du jour. (https://tarkalabs.com/)

Sreedev Kodichath
Sreedev Kodichath

Written by Sreedev Kodichath

Senior Software Engineer @ Tunecore. Ruby, Elixir, Javascript C & Rust. Amateur Radio Operator — KD2ZWB/VU2JWE. www.sree.dev. Brooklyn, NYC.

No responses yet