This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function that inserts a specified string into another string. It uses java's StringBuilder. | |
* Usage: insertStringInString("dogs cats", "and", 4) -> "dogs and cats" | |
* @param string - The main string that should contain the new piece | |
* @param insertion - The piece to add | |
* @param position - The position from which to add the piece | |
* @return - The final string | |
*/ | |
public static String insertStringInString(String string, String insertion, int position) { | |
// Only insert if the position is > -1 (useful with string.indexOf which returns -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Quick method to remove a specified part of a string | |
* @param remove - the string part to remove | |
* @param from - the original string | |
* @return - the cut string | |
*/ | |
public static String removeStringFromString(String remove, String from) { | |
char lastCharacter = remove.charAt(remove.length() - 1); | |
int cutStart = from.lastIndexOf(lastCharacter) + 1; | |
return from.substring(cutStart); |