2016-12-03 40 views
0

(作業免責聲明) 我正在嘗試爲128 Ascii中找不到的特殊字符創建地圖。 當找到角色時,我需要用靠近它的Ascii中的一個角色替換它。該數據是從有文字像製作地圖以用ASCII字符替換特殊字符

E.g

543|Misèrables, Les (1995) 
543|Miserables, Les (1995) 

第二行是應如何照顧我正確地使用我的地圖文件來英寸

這裏是我的地圖

Map<Integer, Character> ascMap = new HashMap<>(); 
//ascMap.put(246, 'o'); 
//ascMap.put(232, 'e'); 

ascMap.put('ö' , 'o'); 
ascMap.put('è' , 'e'); 

和我的代碼的其餘部分。

String newMovieLine = null; 
String store = null; 
String empty = null; 

int movieCount = 0; 
int ascCount = 0; 

//System.out.println(ascMap); 

    try { 
      FileReader readFile = new FileReader(movieFile); 

      BufferedReader buffMovie = new BufferedReader(readFile); 


      //read while stream is not empty 
      while ((empty = buffMovie.readLine()) != null){ 

        if(isAscii(empty) == false){ 

        store = empty; 
        newMovieLine = empty; 

     movieCount++;       
     System.out.println(store); //print each line withnon ascii characters 

        System.out.println(" "); 

        } 

        //check the value for ascii 
        for(int j = 0, n = empty.length(); j < n; j++){ 

        char asc = empty.charAt(j); 

          if(asc > 127){ 

          ascCount++; 

          } 
          if(asc == 246){ 

          asc = ascMap.get(246); 
          newMovieLine = newMovieLine.replace('ö' , 'o'); 
          } 

          else if(asc == 232){ 

          asc = ascMap.get(232); 
        newMovieLine = newMovieLine.replace('è','e'); 

}}} 
+0

你的問題是什麼? –

+0

當前版本不會替換字符。所以我的問題是我做錯了什麼?我用我的if語句中的特殊字符取代了232,沒有結果。我做了無數其他的事情,但我不知道該怎麼做。 – akrutke

回答

0

在地圖中聲明,你有Map<Integer,Character>

應該是Map<Character,Character>

470如何治療嗎? :p

+0

粗糙。這是一個粗糙的學期。但我實際上發現替換我的輸入字符串更容易。但是沒有,這是實際的地圖聲明。 – akrutke