Welcome to Dream.In.Code
Become a Java Expert!

Join 149,491 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,286 people online right now. Registration is fast and FREE... Join Now!




Iso: Program help

 
Reply to this topicStart new topic

Iso: Program help, removing charcters from text

ProGraM
20 Mar, 2007 - 03:59 PM
Post #1

D.I.C Head
**

Joined: 28 Sep, 2005
Posts: 92



Thanked: 2 times
My Contributions
I am so close to dont thanks to previous help in last post. Now all i need is to remove multi-comments and /* */ comments heres my program. Further explanations below and what i need.

CODE

import java.io.*;
import java.util.ArrayList;
public class RemoveText
{
    public static void main(String[] args)throws IOException
    {
        RemoveText Remove = new RemoveText();
        Remove.PrintInFile();
    }
    public static void PrintInFile()throws IOException
    {
        String Text = null;
        Text = new String();
        boolean Quotes = false, Comment = false;
        ArrayList<String>Line = new ArrayList();
        FileReader ReadFile = new FileReader("InFile.txt");
        BufferedReader InFile = new BufferedReader(ReadFile);
        FileOutputStream OutFile = new FileOutputStream("OutFile.txt");
        PrintStream print = new PrintStream(OutFile);
            for(int x = 0;(Text = InFile.readLine()) != null; x++)
            {
                Line.add(Text);
            }
            for(int x = 0; x < Line.size(); x++)
            {
                if(((Line.get(x)).indexOf("//") != -1))
                {
                    Line.set(x, (Line.get(x)).substring(0, (Line.get(x)).indexOf("//")));
                }
                if(((Line.get(x)).indexOf("/*") != -1))
                {
                    if((Line.get(x)).indexOf("*/") != -1)
                    {
                        Comment = true;
                    }
                }
            }
                for(int x = 0; x < Line.size(); x++)
                {
                    print.println(Line.get(x));
                }
    }
}


Heres the input file before:
CODE

/************************************************************

Gee a line of stars

*/

#include <iostream.h> //whoops comment
#include <string.h>
#include <iomanip.h> //comment line

int main() /* comment for main   */
{
    int j; /*declares variable */
    string name = "Your famous name"; // comment // followed by another line comment
    /*
       could this be a //
           multi-line comment? //*/
    cout << "/*\"\"Who are you? \n";
    getline(cin,name);  // /*
    
    cout << "\\**/*/*/* You entered */*/*/* "<< name << "*/*/*/*\n";

    /*think finished, done!*/
    return 0;
}//end of main


Ok heres the problem, my program after executed looks like this:
it should get rid of all the comments but does only // not /**/ or multi lined comments sad.gif help plz
CODE

/************************************************************

Gee a line of stars

*/

#include <iostream.h>
#include <string.h>
#include <iomanip.h>

int main() /* comment for main   */
{
    int j; /*declares variable */
    string name = "Your famous name";
    /*
       could this be a
           multi-line comment?
    cout << "/*\"\"Who are you? \n";
    getline(cin,name);  
    
    cout << "\\**/*/*/* You entered */*/*/* "<< name << "*/*/*/*\n";

    /*think finished, done!*/
    return 0;
}


Now this is what it should look like ater program is executed:
[code]


#include <iostream.h>
#include <string.h>
#include <iomanip.h>

int main()
{
int j;
string name = "Your famous name";
cout << "/*\"\"Who are you? \n";
getline(cin,name);

cout << "\\**/*/*/* You entered */*/*/* "<< name << "*/*/*/*\n";

return 0;
}
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 05:26PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month