Code with Finding: |
class HtmlUtilities {
/**
* Removes the comments sections of a String.
*
* @param string
* the original String
* @param startComment
* the String that marks the start of a Comment section
* @param endComment
* the String that marks the end of a Comment section.
* @return the String stripped of its comment section
*/
public static String removeComment(String string, String startComment,
String endComment) {
StringBuffer result = new StringBuffer();
int pos = 0;
int end = endComment.length();
int start = string.indexOf(startComment, pos);
while (start > -1) {
result.append(string.substring(pos, start));
pos = string.indexOf(endComment, start) + end;
start = string.indexOf(startComment, pos);
}
result.append(string.substring(pos));
return result.toString();
}
}
|