-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathStringUtilities.java
More file actions
59 lines (53 loc) · 1.72 KB
/
StringUtilities.java
File metadata and controls
59 lines (53 loc) · 1.72 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class StringUtilities {
/**
* @param input value to be returned
* @return `input`
*/
public String returnInput(String input) {
return input;
}
/**
* @param baseValue value to be added to
* @param valueToBeAdded value to add
* @return the concatenation of `baseValue` and `valueToBeAdded`
*/
public String concatenate(String baseValue, String valueToBeAdded) {
return baseValue.concat(valueToBeAdded);
}
/**
* @param valueToBeReversed value to be reversed
* @return identical string with characters in opposite order
*/
public String reverse(String valueToBeReversed) {
String revString = "";
for (int in = valueToBeReversed.length()-1; in>=0; in--) {
revString += valueToBeReversed.charAt(in);
}
return revString;
}
/**
* @param word word to get middle character of
* @return middle character of `word`
*/
public Character getMiddleCharacter(String word) {
int len = word.length();
return word.charAt(len/2);
}
/**
* @param value value to have character removed from
* @param charToRemove character to be removed from `value`
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
String res = value.replaceAll("(?i)" + charToRemove, "");
return res;
}
/**
* @param sentence String delimited by spaces representative of a sentence
* @return last `word` in sentence
*/
public String getLastWord(String sentence) {
String[] words = sentence.split(" ");
return words[words.length - 1];
}
}