forked from anthonynsimon/java-ds-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSanitizer.java
More file actions
27 lines (22 loc) · 712 Bytes
/
Sanitizer.java
File metadata and controls
27 lines (22 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.anthonynsimon.algorithms.strings;
public final class Sanitizer {
public static String sanitize(String str, char[] blacklist) {
int strLength = str.length();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < strLength; i++) {
char currentChar = str.charAt(i);
if (!charInArray(currentChar, blacklist)) {
sb.append(currentChar);
}
}
return sb.toString();
}
private static boolean charInArray(char c, char[] charArray) {
for (char currentChar : charArray) {
if (currentChar == c) {
return true;
}
}
return false;
}
}