user317033
user317033

Reputation:

Java - Converting a German accented characters to two letter equivalents

I need to convert a string containing accented German letters to their two letter equivalents as follows:

ae = ä | oe = ö | ue = ü | sz = ß

How can I do this in Java? I see their are other questions where the accents are simply removed, but I can't figure out how to change it to do what I want. I'm completely new to Java, so don't even know how to start approaching this.

Is there a way to get rid of accents and convert a whole string to regular letters?

Upvotes: 0

Views: 1071

Answers (1)

de3
de3

Reputation: 2000

String a="wörd";
String b=a.replaceAll("ö", "oe");
System.out.println(b);

This will print woerd . you can concatenate replaces

 String a="wördsämple";
String b=a.replaceAll("ö", "oe").replaceAll("ä","ae");
System.out.println(b);

This will print woerdsaemple, and so on...

Upvotes: 1

Related Questions