OVH Cloud OVH Cloud

String compareTo et lettres accentuées

5 réponses
Avatar
yvon.thoravalNO-SPAM
Bonjour,

y-a-t'il un moyen simple pour convertir une chaine accentuée en une
chaine NON-accentuée en java.

Je veux autrement qu'en l'implémentant par soi-même ?

--
yt

5 réponses

Avatar
Thibaut Desmarest
Yvon Thoraval wrote:
Bonjour,

y-a-t'il un moyen simple pour convertir une chaine accentuée en une
chaine NON-accentuée en java.

Je veux autrement qu'en l'implémentant par soi-même ?



Si tu fais un compareIgnoreCase() ca marche pas ?

Thibaut

Avatar
yvon.thoravalNO-SPAM
Thibaut Desmarest wrote:

Si tu fais un compareIgnoreCase() ca marche pas ?


non, les é passent en bout de l'alphabet...
--
yt

Avatar
Marc Petit-Huguenin
Yvon Thoraval wrote:
Thibaut Desmarest wrote:


Si tu fais un compareIgnoreCase() ca marche pas ?



non, les é passent en bout de l'alphabet...


String[] strings = new String[] { "a", "e", "i", "o", "u", "â", "æ", "è",
"á", "é", "ù" };

SortedSet set = new TreeSet();
set.addAll(Arrays.asList(strings));
System.out.println(set);

set = new TreeSet(Collator.getInstance(Locale.FRANCE));
set.addAll(Arrays.asList(strings));
System.out.println(set);


Avatar
yvon.thoravalNO-SPAM
Marc Petit-Huguenin wrote:

set = new TreeSet(Collator.getInstance(Locale.FRANCE));


Super ! Merci beaucoup, je ne connaissais pas Collator...

Mais pourquoi ont-ils choisi cete ordre entre majuscules et minuscules :
String[] strings = new String[] { "¼", "½", "Æ", "æ", "U", "O", "I",
"E", "A", "a", "É", "Ê", "Â", "Ä", "ç", "Ç", "e", "i", "o", "u", "â",
"æ", "è", "á", "é", "ù", "À"};

[A, E, I, O, U, a, e, i, o, u, À, Â, Ä, Æ, Ç, É, Ê, á, â, æ, ç, è, é, ù,
¼, ½]
[a, A, á, À, â, Â, Ä, æ, Æ, ç, Ç, e, E, é, É, è, Ê, i, I, o, O, ½, ¼, u,
U, ù]

c'est une habitude *nix ??? (j'aurais choisi l'inverse, je passerai en
uppercase donc...)

Meci encore pour ce "Collator"...
--
yt

Avatar
yvon.thoravalNO-SPAM
Yvon Thoraval wrote:

Mais pourquoi ont-ils choisi cete ordre entre majuscules et minuscules :


inutile de faire toUpperCase() :

Collator frCollator = Collator.getInstance(Locale.FRANCE);
frCollator.setStrength(Collator.SECONDARY);
int comp = frCollator.compare("états", "États");
System.out.println("comp");

donne 0...
--
yt