Untitled
unknown
java
2 years ago
580 B
19
Indexable
Never
public static String stripComments(String text, String[] commentSymbols) { String[] lines = text.split("\n"); List<String> list = Arrays.asList(commentSymbols); List<String> result = new ArrayList<String>(); lines: for (String line : lines){ for (int i = 0; i < line.length(); i++) { if (list.contains(String.valueOf(line.charAt(i)))) { result.add(line.substring(0, i).stripTrailing()); continue lines; } } result.add(line.stripTrailing()); } return String.join("\n", result); }