Skiping Comments Using Scanner()

S

smescal

I am trying to read in a Java source code file, line by line, using
java.util.Scanner but I want to ignore commented sections and just work
with the code.

If anyone could offer any advice about how to skip the commented
sections I would greatly appreciate it .
 
C

Carramba

I am trying to read in a Java source code file, line by line, using
java.util.Scanner but I want to ignore commented sections and just work
with the code.

If anyone could offer any advice about how to skip the commented
sections I would greatly appreciate it .
can you try to filter conten after you have read it in? put every line in
separe string and something like if // in line go to next line and if /*
is in string skip all untill found */ ?


--

Thanx in advance
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my speling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.
 
S

smescal

Carramba said:
can you try to filter conten after you have read it in? put every line in
separe string and something like if // in line go to next line and if /*
is in string skip all untill found */ ?


--

Thanx in advance
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my speling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.


Yeah I have been trying something similar to that and it works but the
code is
very long and a bit messy. I am now hoping I can do something a bit
more
elegant using .useDelimiter() or .skip() and some sort of regex.

Thanks for the input all the same... and your English ain't so bad
 
S

smescal

Carramba said:
can you try to filter conten after you have read it in? put every line in
separe string and something like if // in line go to next line and if /*
is in string skip all untill found */ ?


--

Thanx in advance
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my speling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.


Yeah I have been trying something similar to that and it works but the
code is
very long and a bit messy. I am now hoping I can do something a bit
more
elegant using .useDelimiter() or .skip() and some sort of regex.

Thanks for the input all the same... and your English ain't so bad
 
A

Abhijat Vatsyayan

If you are trying to parse java code, you might consider using antlr (or
something similar).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top