find - Java: Style-Correcting Code: finding comment -


i'm writing these algorithms style-correcting program makes adjustments java source file, can compile without error. set read file line-by-line.

right now, i'm having trouble writing 2 methods/algorithms which

  1. determine if current line (string) has comments, and
  2. finds comment starts

i have:

 public static int findcomment (string textline) {               int endofcode = textline.lastindexof(";  ");               return textline.indexof("//", endofcode);             }          public static boolean hascomment (string textline) {            if (textline.contains("//"))             {               return true;            }             else            {               return false;            }         } 

i know incorrect because can have code, , comments, contain " ; // ; //" comments. tried other conditional statements without success.

hello don't explain problem have think should escape backslash characters when working indexof function.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -