Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void stripComments(Scanner in) {
- String output=""; // iki tip comment oldugundan dosyayi iki kere islemeye karar verdim
- // output bunun icin tanimlandi
- // "//" ile baslayan commentler icin
- while (in.hasNextLine()) {
- String line = in.nextLine();
- int commentStart=line.indexOf("//"); // Comment'in basladigi yeri buluyoruz
- if (commentStart == -1) // eger comment yoksa indexOf -1 dondurur
- output+=line+"\n";
- else // eger comment varsa
- output+=line.substring(0,commentStart)+"\n";
- }
- while (output.indexOf("/*") != -1) {
- String beforeComment = output.substring(0,output.indexOf("/*"));
- String afterComment = output.substring(output.indexOf("*/")+2);
- output=beforeComment+afterComment;
- }
- System.out.print(output);
- }
Add Comment
Please, Sign In to add comment