Advertisement
sedran

StripComments

Dec 21st, 2010
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. public static void stripComments(Scanner input) {
  2.    String s = "";
  3.    while( input.hasNextLine() ) {
  4.       s += input.nextLine() + "\n";
  5.    }
  6.    while( s.indexOf("/*")>=0 ) {
  7.       int first = s.indexOf("/*");
  8.       int second = s.indexOf("*/");
  9.       s = s.substring(0, first) + s.substring(second+2);
  10.    }
  11.    while( s.indexOf("//") >= 0 ) {
  12.       int first = s.indexOf("//");
  13.       String f = s.substring(0, first);
  14.       String g = s.substring(first+2);
  15.       int a = g.indexOf("\n");
  16.       int second = f.length() + a;
  17.       s = s.substring(0, first) + s.substring(second+2);
  18.    }
  19.    System.out.print(s);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement