123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package QuizWeek1;
  2. public class StringUtilities {
  3. public Character getMiddleCharacter(String word){
  4. char middle;
  5. int mid;
  6. String midString = "";
  7. //find index of middle letter
  8. mid = ((word.length())/2);
  9. System.out.println(mid);
  10. //midString = word.substring(mid, (mid+1));
  11. middle = word.charAt(mid);
  12. // char[] charArray = word.toCharArray();
  13. // middle = charArray[mid];
  14. //System.out.println(middle);
  15. return middle;
  16. }
  17. public String removeCharacter(String value, char charToRemove){
  18. String newWord = value.substring(0, charToRemove-1) + value.substring((charToRemove-1) + 1);
  19. System.out.println(newWord);
  20. return newWord;
  21. }
  22. public String getLastWord(String value) {
  23. int i = 0;
  24. int pos;
  25. int len = (value.length()-1);
  26. System.out.println(len);
  27. int count = len;
  28. char[] charArray = value.toCharArray();
  29. //loop through until find last space
  30. while (charArray[count] != ' '){
  31. count--;
  32. }
  33. String last = value.substring(count + 1);
  34. System.out.println(last);
  35. return last;
  36. }
  37. }