#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    18
    Rep Power
    0

    String questions.


    What I'm trying to do is read in from a file, and then every time a specific character appears in the file I want to insert a variable directly directly after it and then output the same thing I read in except with the variable inserted in.

    So if the line was
    Hey how's ( it going?
    I would want it to read
    Hey how's (variable it going?

    How would I do this?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    18
    Rep Power
    0
    Well I managed to think of something myself. But I still need help.
    The problem with this is every line that has a "{" in it is output twice one without the counter added and one with. I'd like someone to point out how I can make it work. Here is the section of my original code.

    Code:
    while(in.hasNextLine()) {
    StringBuffer line = new StringBuffer(in.nextLine());
    out.println(line);
    for(int i = 0; i <line.length(); i++) 
    {
    if(line.charAt(i)=='{')
    {
    counter++;
    line.insert(i+1, counter);
    out.println(line);
    }

IMN logo majestic logo threadwatch logo seochat tools logo