-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringManipulation.java
More file actions
32 lines (27 loc) · 904 Bytes
/
StringManipulation.java
File metadata and controls
32 lines (27 loc) · 904 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
public class StringManipulation {
public String trimAndConcat(String string1, String string2) {
return string1.trim().concat(string2.trim());
}
public Integer getIndexOrNull(String input, char c) {
if (input.indexOf(c) == -1) {
return null;
}
return input.indexOf(c);
}
public Integer getIndexOrNull(String input, String sub) {
if (input.indexOf(sub) == -1) {
return null;
}
return input.indexOf(sub);
}
public String concatSubstring(String input, int idxA, int idxB, String replacement) {
String substr;
try {
substr = input.substring(idxA, idxB);
} catch (IndexOutOfBoundsException e) {
System.out.println(String.format("Exception caught: %s", e));
substr = "whoops!";
}
return substr.concat(replacement);
}
}