Is there any way to replace any foreign characters for example: ã, ä to a, Ĉ, ć to c etc. I mean to leave simple letters like a-Z, without any additional things.
Asked
Active
Viewed 198 times
1
-
1Tons of ways. Do you have a language with which you wish to accomplish this task? – Milo LaMar Jan 14 '12 at 23:25
-
2See http://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net – Arnold Zokas Jan 14 '12 at 23:25
-
The heading and the text of the question are contradictory, as the text refers to *replacing* characters. – Jukka K. Korpela Jan 14 '12 at 23:39
1 Answers
3
You can do this regular expression, if regexps are available to you:
str = str.replaceAll("[^a-zA-Z]", ""); //Assuming it to be a Java String
If you wish to normalize your text, however, you should do as the accepted answer for this question suggests: Remove diacritical marks (ń ǹ ň ñ ṅ ņ ṇ ṋ ṉ ̈ ɲ ƞ ᶇ ɳ ȵ) from Unicode chars
If you need to achieve the same thing in PHP you can write:
echo iconv('UTF-8', 'US-ASCII//TRANSLIT', 'asdaśćż,ąółwe,ÄĄ;ú');

Community
- 1
- 1

Milad Naseri
- 4,053
- 1
- 27
- 39
-
This removes characters with diacritical marks _completely_, rather than "flattening" them to their ASCII equivalents. – sarnold Jan 14 '12 at 23:29
-
The question DOES clearly state *removing* the characters, doesn't it? – Milad Naseri Jan 14 '12 at 23:32
-
-
Ah, yes. Seems I did not read the question carefully enough. Thanks for pointing it out. – Milad Naseri Jan 14 '12 at 23:35
-
-
Thanks for answer, but the problem is, that I need to do it in php. – Wojciech Kulik Jan 15 '12 at 00:11
-
If found one solution, it seems to work quite well: echo iconv('UTF-8', 'US-ASCII//TRANSLIT', 'asdaśćż,ąółwe,ÄĄ;ú'); – Wojciech Kulik Jan 15 '12 at 00:20
-
-
@Wojciech: if that works for you, please add it as an answer so it can be available to future visitors. :) – sarnold Jan 15 '12 at 00:22
-
@sarnold - you're right, but I've thought then about some general idea, I didn't know that it would be so simple :). I've tried to add it as answer, but i haven't got enough "points" – Wojciech Kulik Jan 15 '12 at 00:37
-
It's because you haven't accepted answers to 67% of the questions you've asked, so you've not gotten any reputations for it. :) – Milad Naseri Jan 15 '12 at 00:39
-
@Wojciech: I see. I've gone through some of your posts and added some reputation points, you'll get there quickly. – sarnold Jan 15 '12 at 00:52
-
sarnold thanks:)! @MiladNaseri: it's because people didn't know or didn't answer to half of my questions :). – Wojciech Kulik Jan 15 '12 at 01:03
-
:) I see. Well, it's only fair that you shouldn't accept an answer unless it satisfies you. Anyways, we here are delighted to have you around. – Milad Naseri Jan 15 '12 at 01:05