I'm building a word list that contains Cyrillic letters and I'm converting them into their pronounce form. E.g. č = ч = ch, š = ш = sh, ḱ = кј ǵ = ѓ = gj. So far I tried to use the Unicode form, and cyrillic letters in their original form in the change method, but each time the conversion fails. The last change I'm willing to try is to change the encoding. What am I doing wrong?!
public class Main {
private static List<String> passwordList = new ArrayList<>();
public static void main(String[] args) throws IOException {
String read = null;
String toBeModified = null;
try {
BufferedReader br = new BufferedReader(new FileReader("input.txt"));
while ((read = br.readLine()) != null) {
toBeModified = read;
passwordList.add(change(toBeModified));
}
} catch(Exception e) {
e.printStackTrace();
}
save(passwordList);
}
public static void save(List<String> passwordList) throws IOException {
BufferedWriter br = new BufferedWriter(new FileWriter("saved.txt"));
for (int i = 0; i < passwordList.size(); i++) {
if (passwordList.get(i).isEmpty() == false) {
br.write(passwordList.get(i));
br.newLine();
}
}
}
//problem here
public static String change(String str){
String newStr = "";
if (str.contains("\u010C")){
newStr = str.replace("\u010D","ch");
}else if (str.contains("\u017E")){//U+017E
newStr = str.replace("\u017E","zh");
}else if (str.contains(",")){
newStr = str.replace(",","");
newStr.trim();
} else if (str.contains(";")){
newStr = str.replace(";","");
newStr.trim();
} else if (str.contains(".")){
newStr = str.replace(".","");
newStr.trim();
} else if (str.contains(":")) {
newStr = str.replace(":","");
newStr.trim();
} else if (str.contains("(\u0160")){
newStr = str.replace("(\u0160", "sh");
} else if (str.contains("\u1E31")){
newStr = str.replace("\u1E31","kj");
}else if (str.contains("(")){
newStr = str.replace("(","");
newStr.trim();
}else if (str.contains(")")){
newStr = str.replace(")","");
newStr.trim();
//test to check if works - works like this
// }else if (str.contains("a")){
// newStr = str.replace("a","TestToSeeIfWorks");
}
return newStr;
}
}