1234567891011121314151617181920212223242526272829303132333435363738394041 |
- public class StringUtilities {
- public Character getMiddleCharacter(String word){
- char midChar = word.charAt(word.length() / 2);
- return midChar;
- }
-
- public String removeCharacter(String value, char charToRemove){
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < value.length(); i++) {
- if (value.charAt(i) == charToRemove) {
- continue;
- } else {
- sb.append(value.charAt(i));
- }
- }
-
- String newValue = sb.toString();
-
- return newValue;
- }
-
- public String getLastWord(String value) {
- // Cycle through each element of the string.
- // If the element is a space, the word is the space
-
- StringBuilder sbLastWord = new StringBuilder();
-
- for (int i = value.length() - 1; i > 0; i--) {
- if (value.charAt(i) == ' ') {
- sbLastWord.append(value.substring(i + 1, value.length()));
- break;
- }
- }
-
- String lastWord = sbLastWord.toString();
-
- return lastWord;
- }
- }
|