0

我正在构建一个包含西里尔字母的单词列表,并将它们转换为它们的发音形式。例如 č = ч = ch、š = ш = sh、ḱ = кј ǵ = ѓ = gj。到目前为止,我尝试使用Unicode形式,并在更改方法中以原始形式的西里尔字母,但每次转换都失败。我愿意尝试的最后一个更改是更改编码。我究竟做错了什么?!

  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;

    }

}
4

0 回答 0