123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
-
- /**
- * Created by dan on 6/14/17.
- */
- public class StringUtilities {
- /**
- * @return `Hello World` as a string
- */
- public static String getHelloWorld() {
-
- String x = "Hello World";
- return x;
- }
-
- /**
- * @param firstSegment a string to be added to
- * @param secondSegment a string to add
- * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
- */
- public static String concatenation(String firstSegment, String secondSegment){
- String complete = firstSegment + secondSegment;
- return complete;
- }
-
- /**
- * @param firstSegment a string to be added to
- * @param secondSegment a string to add
- * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
- */
- public static String concatenation(int firstSegment, String secondSegment){
- String complete = firstSegment + secondSegment;
- return complete;
-
- }
-
- /**
- * @param input a string to be manipulated
- * @return the first 3 characters of `input`
- */
- public static String getPrefix(String input){
-
- if(input.length()<= 3){
- return input;
- }
- return input.substring(0,3);
-
- }
-
- /**
- * @param input string to be manipulated
- * @return the last 3 characters of `input`
- */
- public static String getSuffix(String input){
-
- /*
- for(int i = input.length(); i>=0; i-- ){
-
- hold= hold + input.charAt(i);
-
- }
- */
- return input.substring(input.length()-3,input.length());
-
-
- }
- /**
- * @param inputValue the value to be compared
- * @param comparableValue the value to be compared against
- * @return the equivalence of two strings, `inputValue` and `comparableValue`
- */
- public static Boolean compareTwoStrings(String inputValue, String comparableValue){
-
- if(inputValue.equals(comparableValue)){
- return true;
- }
- return false;
-
- }
-
- /**
- * @param inputValue the value input from user
- * @return the middle character of `inputValue`
- */
- public static Character getMiddleCharacter(String inputValue){
- int middle;
- char sum1;
-
- if( inputValue.length() % 2 == 0){
- middle = inputValue.length()/2-1;
- sum1 = inputValue.charAt(middle);
-
- }else{
- middle = inputValue.length()/2;
- sum1 = inputValue.charAt(middle);
-
- }
- return sum1;
-
- }
-
- /**
- * @param spaceDelimitedString a string, representative of a sentence, containing spaces
- * @return the first sequence of characters
- */
- public static String getFirstWord(String spaceDelimitedString){
- /*
- int i= spaceDelimitedString.indexOf("");
- String wordsweneed = spaceDelimitedString.substring(i,spaceDelimitedString.length());
- String wordwewant = spaceDelimitedString.substring(i);
-
- return wordwewant;
- */
-
- return spaceDelimitedString.split(" ")[0];
- }
-
- /**
- * @param spaceDelimitedString a string delimited by spaces
- * @return the second word of a string delimited by spaces.
- */
- public static String getSecondWord(String spaceDelimitedString){
- int i= spaceDelimitedString.indexOf("");
- String wordsweneed = spaceDelimitedString.substring(i,spaceDelimitedString.length());
-
-
- return spaceDelimitedString.split(" ")[1];
- }
-
- /**
- * @param stringToReverse
- * @return an identical string with characters in reverse order.
- */
- public static String reverse(String stringToReverse){
-
- String hold = "";
-
- for(int i = stringToReverse.length()-1; i>=0; i-- ){
-
- hold= hold + stringToReverse.charAt(i);
-
- }
- return hold;
- }
- }
|