Results 1 to 3 of 3

Thread: replaceAll

  1. #1
    Andrea is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default replaceAll

    Hi there =)
    In this program, the program file is read and stored in char[]-array "temp". Afterwards the file is stored in txt-file.
    Method replaceAll() makes that all letters "i" are turned into "w" in this example.
    How can I count everytime a letter is exchanged?

    package inpOutBeisp;
    import java.io.*;
    public class FileCopyCharChange{
    public static void main(String[] args){
    File dir = new File(".\\inpOutBeisp");
    File fil = new File(dir, "FileCopyCharChange.java");
    File copy = new File("FileCopyCharChange.txt");

    FileReader fr;
    FileWriter fw;

    char[] temp = new char[1000];
    try{
    fr = new FileReader(fil);
    fw = new FileWriter(copy);
    int arrayLaenge = fr.read(temp);
    fr.close();
    String s = new String(temp, 0, arrayLaenge);
    fw.write(s.replaceAll("i", "w") + "\n", 0, arrayLaenge); //replaceAll
    //fw.write(s, 0, arrayLaenge);
    fw.write("/* Kommentar am Ende der Datei*/");
    fw.close();
    }
    catch(FileNotFoundException ffe){
    System.out.println("Datei nicht gefunden");
    }
    catch(Exception e){}
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: replaceAll

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: replaceAll

    Member Andrea is banned for 1 month for violation of paragraph 5 of the Forum Rules. Two posts by the member have been removed from public view.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Add an exception in a replaceAll method
    By nikoulini85 in forum New To Java
    Replies: 7
    Last Post: 10-10-2012, 11:37 AM
  2. The meaning of replaceAll
    By herolua in forum New To Java
    Replies: 4
    Last Post: 10-07-2011, 05:18 AM
  3. Problem with replaceAll
    By Timmy in forum New To Java
    Replies: 6
    Last Post: 06-06-2011, 04:51 PM
  4. replaceAll Problem
    By steve_m in forum New To Java
    Replies: 3
    Last Post: 12-22-2010, 01:09 PM
  5. Regular Expressions and String.replaceAll()
    By meta1203 in forum New To Java
    Replies: 1
    Last Post: 11-24-2010, 11:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •