2013-11-25 25 views
0

我有一個文檔,我必須用數字以升序替換一些特殊字符。 我已標記那些字符爲 「& &」,我不得不更換第一14 & & 1,接下來的14 & & 2,接下來的14 & & 3等....接下來的14 & & 250。 有沒有更好更快的方法來做到這一點。 謝謝..Notepad ++用數字替換一系列字符

+0

你有沒有教如何使用語言如C++使用 libary改變文件中的數據讀取和寫入,然後將數據返回到一個文件? –

+0

是的,但我只能想......我不知道任何C++。 – swapna

+0

你喜歡什麼語言? :) –

回答

3

我能想到的完成在記事本+ +你的任務的唯一方法,是使用Python腳本插件。

  1. 從插件管理器或從official website安裝Python腳本插件。
  2. 然後進入插件> Python腳本>新腳本。爲新文件選擇一個文件名(例如replace_series.py)並複製下面的代碼。
  3. 運行插件> Python腳本>腳本> replace_series.py,一個新的選項卡將顯示所需的結果。
number = 1 
content = editor.getText() 
while "&&" in content: 
    content = content.replace("&&", str(number), 14) 
    number += 1 

notepad.new() 
editor.addText(content) 
+0

如果我有「[0]」,我必須用「[1]」,「[2]」等替換它...... – swapna

+0

然後在上面的代碼中將'&&'更改爲'[0 ]和'content.replace(「&&」,str(number),14)'到'content.replace(「[0]」,「[」+ str(number)+「]」,14)'。 – psxls

+0

現在我可以完成我的工作了,這是一個出色的解決方案...... – swapna

1

你可以在Java試試這個, 這不是很漂亮,但它應該工作

private void readAndWrite() { 
    String [] lines = new String[1000]; 
    try { 
     int n=0; 
     BufferedReader br = new BufferedReader(new FileReader("d:/test.txt")); 


     while (br.readLine()!=null) { 
      lines[n]=br.readLine(); 
      n++;     
     } 

     FileWriter fw = new FileWriter("d:/test2.txt"); 
     BufferedWriter bw = new BufferedWriter(fw); 
     int num =1; 
     int count=1; 
     String test=""; 
     int p=0; 
     while (lines[p]!= null) { 
      bw.write(lines[p].replace("&&", Integer.toString(num))+"\n"); 
      bw.newLine(); 
      bw.flush(); 
      count++; 
      p++; 
      if (count==15) { 
       count=1; 
       num++; 
      } 

     } 
     fw.close(); 


    }catch (NullPointerException e) { 

    } 
    catch (FileNotFoundException e) { 

     e.printStackTrace(); 
    } catch (IOException e) { 

     e.printStackTrace(); 
    }