StringUtilities.java 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. if (word.length() % 2 != 0) {int length = word.length() - 1;
  4. int middle = length / 2;
  5. String math = String.valueOf(middle + 1);
  6. int halfway = Integer.valueOf(math);
  7. String thechar = word.substring(halfway - 1, halfway);
  8. char itsthechar = thechar.charAt(0);
  9. return itsthechar;} else {
  10. int length = word.length();
  11. int middle = length / 2;
  12. String math = String.valueOf(middle + 1);
  13. int halfway = Integer.valueOf(math);
  14. String thechar = word.substring(halfway - 1, halfway);
  15. char itsthechar = thechar.charAt(0);
  16. return itsthechar;
  17. }}
  18. public String removeCharacter(String value, char charToRemove){
  19. String thechar = String.valueOf(charToRemove);
  20. String format = value.replaceAll(thechar,"");
  21. return format;
  22. }
  23. public String getLastWord(String value) {
  24. String[] splitem = value.split("\\s+");
  25. int length = splitem.length;
  26. return splitem[length-1];
  27. }
  28. }