I want to change this sentence :
Et ça sera sa moitié.
To :
Et ca sera sa moitie.
Is there an easy way to do this in Java, like I would do in Objective-C ?
NSString *str = @"Et ça sera sa moitié."; NSData *data = [str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *newStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
To remove all accents in a string using vanilla JavaScript use the normalize function supplemented by a string replace . The normalize() method returns the Unicode Normalization Form of the string.
replace(/[^a-z0-9]/gi,'') . However a more intuitive solution (at least for the user) would be to replace accented characters with their "plain" equivalent, e.g. turn á , á into a , and ç into c , etc.
Finally, I've solved it by using the Normalizer
class.
import java.text.Normalizer; public static String stripAccents(String s) { s = Normalizer.normalize(s, Normalizer.Form.NFD); s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", ""); return s; }
Maybe the easiest and safest way is using StringUtils
from Apache Commons Lang
StringUtils.stripAccents(String input)
Removes diacritics (~= accents) from a string. The case will not be altered. For instance, 'à' will be replaced by 'a'. Note that ligatures will be left as is.
StringUtils.stripAccents()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With