5

Is there is a more efficient way to remove accents from string without make an big array with the characters to replace?

For example:

removeaccents("áèfoo")

Output:

aefoo

In the ASCII table there no accents, I have no idea how to do this. Thanks in advance. :)

Community
  • 1
  • 1
Jack
  • 16,276
  • 55
  • 159
  • 284

1 Answers1

8

Sounds like you're looking for unac(). From the man page:

unac is a C library that removes accents from characters, regardless of the character set (ISO-8859-15, ISO-CELTIC, KOI8-RU...) as long as iconv(3) is able to convert it into UTF-16 (Unicode).

I couldn't find the download page (I think it's meant to be here, but the link is currently 404ing). If you're on ubuntu, you can get it with:

sudo apt-get install libunac1-dev

Assuming you're using gcc, once it's installed you'll need to add -lunac to your compiler options (to tell the compiler to link with the unac library).

Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
  • Thanks very much. :) I downloaded and installed, but when I try link and compile I get the following error: `/tmp/ccAKGVl9.o: In function `main': ILD.c:(.text+0x651): undefined reference to `unac_string' collect2: ld returned 1 exit status ` my code: `#include // ... char* out = 0; size_t out_length = 0; if(unac_string("ISO-8859-1", "été", strlen("été"), &out, &out_length)) { printf("unac_string"); } else { printf("%.*s0", out_length, out); free(out); }` – Jack Mar 14 '12 at 15:59
  • I solved using `-lunac` option on `gcc` and changed `ISO-8859-1` to `UTF-8` encoding and works fine now. Thanks you very much :) – Jack Mar 14 '12 at 21:02