-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringChecker.java
More file actions
34 lines (27 loc) · 894 Bytes
/
StringChecker.java
File metadata and controls
34 lines (27 loc) · 894 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
28
29
30
31
32
33
34
package javaFx;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringChecker {
private static String line;
private static final String DEFAULT_SEPARATOR = " ";
private static String SEPARATOR;
StringChecker(String str, String separator) {
line = str;
SEPARATOR = separator;
}
StringChecker(String str) {
new StringChecker(str, DEFAULT_SEPARATOR);
}
public boolean containSymbols(String symbols) {
return line.matches(String.format(".*%s.*", symbols));
}
public String getSymbols(String symbols) {
StringBuilder matched = new StringBuilder();
Pattern p = Pattern.compile(symbols);
Matcher m = p.matcher(line);
while (m.find()) {
matched.append(String.format("%s", m.group() + SEPARATOR));
}
return matched.toString();
}
}