[Acceleo] match/drop Special chars [message #535714] |
Tue, 25 May 2010 11:33 |
Laviale Benoit Messages: 25 Registered: April 2010 Location: Paris |
Junior Member |
|
|
Hi,
I think it's for the moment impossible to do...
I need to match special chars in the an attribute of my artefacts, and after to replace the Special char to an other char.
For example, if I have a class with the name "école", I want to replace é to e ( and to do the same thing for the "ù" "à" "ç" etc )
Is it possible? ( with Something like Regular expressions?)
Thank you in advance
Benoit
[edit] I dont want to use the methode replace(matchstr,replacementstr)
Trainee
Thales Communications France
[Updated on: Tue, 25 May 2010 11:47] Report message to a moderator
|
|
|
Re: [Acceleo] match/drop Special chars [message #535889 is a reply to message #535714] |
Wed, 26 May 2010 08:30 |
|
This is a multi-part message in MIME format.
--------------020301090003010701080807
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Hi Benoit,
If you don't mind using hard-coded mappings (and pray you don't forget
one of the potential mappings), you can use something like
string.replaceAll('éêèë', 'e').replaceAll('ÉÊÈË',
'E').replaceAll('áàãåä', 'a').replace ....
This doesn't really make for the most robust code.
A more reliable solution would be to call a Java service which would do
this :
public String stripDiacritics(String s) {
final String decomposed = Normalizer.normalize(s, Normalizer.Form.NFD);
return decomposed.replaceAll("\\p{M}", "");
}
Take note that the "Normalizer" API has changed in Java 1.6 ; if you're
using Java 1.5 or lower your code would be :
public String stripDiacritics(String s) {
String decomposed = Normalizer.normalize(s, Normalizer.DECOMP, 0);
return decomposed.replaceAll("\\p{M}", "");
}
Regards,
Laurent Goubet
Obeo
Laviale Benoit wrote:
> Hi,
>
> I think it's for the moment impossible to do, but i need to match
> special char in the an attribute of my artefacts, and after to replace
> the Special char to an other char.
>
> For example, if I have a class with the name "école", I want to replace
> é to e ( and to do the same thing for the "ù" "à" "ç" etc )
> Is it possible? ( with Something like Regular expressions?)
>
> Thank you in advance
>
> Benoit
--------------020301090003010701080807
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------020301090003010701080807--
|
|
|
|
Powered by
FUDForum. Page generated in 0.02467 seconds