123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Created by dan on 6/14/17.
  3. */
  4. public class StringUtilities {
  5. /**
  6. * @return `Hello World` as a string
  7. */
  8. public static String getHelloWorld() {
  9. String word = "Hello World";
  10. return word;
  11. }
  12. /**
  13. * @param firstSegment a string to be added to
  14. * @param secondSegment a string to add
  15. * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
  16. */
  17. public static String concatenation(String firstSegment, String secondSegment){
  18. String word = firstSegment + secondSegment;
  19. return word;
  20. }
  21. /**
  22. * @param firstSegment a string to be added to
  23. * @param secondSegment a string to add
  24. * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
  25. */
  26. public static String concatenation(int firstSegment, String secondSegment){
  27. String differentVar = firstSegment + secondSegment;
  28. return differentVar;
  29. }
  30. /**
  31. * @param input a string to be manipulated
  32. * @return the first 3 characters of `input`
  33. */
  34. public static String getPrefix(String input){
  35. String newString = new String();
  36. newString = input.substring(0, 3);
  37. return newString;
  38. }
  39. /**
  40. * @param input a string to be manipulated
  41. * @return the last 3 characters of `input`
  42. */
  43. public static String getSuffix(String input){
  44. String newString = new String();
  45. newString = input.substring(input.length() - 3);
  46. return newString;
  47. }
  48. /**
  49. * @param inputValue the value to be compared
  50. * @param comparableValue the value to be compared against
  51. * @return the equivalence of two strings, `inputValue` and `comparableValue`
  52. */
  53. public static Boolean compareTwoStrings(String inputValue, String comparableValue){
  54. if (inputValue.equals(comparableValue)){
  55. return true;
  56. } else {
  57. } return false;
  58. }
  59. /**
  60. * @param inputValue the value input from user
  61. * @return the middle character of `inputValue`
  62. */
  63. public static Character getMiddleCharacter(String inputValue){
  64. int length = inputValue.length();
  65. if (length % 2 == 0){
  66. return inputValue.charAt((length/2) -1);
  67. }else{
  68. return inputValue.charAt((length -1)/2);
  69. }
  70. }
  71. /**
  72. * @param spaceDelimitedString a string, representative of a sentence, containing spaces
  73. * @return the first sequence of characters
  74. */
  75. public static String getFirstWord(String spaceDelimitedString){
  76. String[] dope = spaceDelimitedString.split(" ");
  77. return dope[0];
  78. }
  79. /**
  80. * @param spaceDelimitedString a string delimited by spaces
  81. * @return the second word of a string delimited by spaces.
  82. */
  83. public static String getSecondWord(String spaceDelimitedString){
  84. String[] yerp = spaceDelimitedString.split(" ",3);
  85. return yerp[1];
  86. }
  87. /**
  88. * @param stringToReverse
  89. * @return an identical string with characters in reverse order.
  90. */
  91. public static String reverse(String stringToReverse){
  92. StringBuilder reversedStringNow = new StringBuilder(stringToReverse);
  93. return reversedStringNow.reverse().toString();
  94. }
  95. }