I have these 2 methods. What I'm currently having troubles is with the cleanWord method. What it can do now is remove only one punctuation either in front or at the back of the string or at both ends. What I'm trying to figure out is how to remove multiple punctuation characters at one go? For example "!!!test" will return "test" after implementing the method. Thank you!
[but do not clean punctuation found in the middle of the word for example "don't"]
public static String cleanWord(String word) { String cleanWord = word; int wordLength = cleanWord.length(); if (isPunctuation(cleanWord.charAt(0)) == true) { cleanWord = cleanWord.substring(1, wordLength); if (isPunctuation(cleanWord.charAt(wordLength - 1)) == true) { cleanWord = word.substring(1, wordLength - 1); } } else if (isPunctuation(word.charAt(wordLength - 1)) == true) { cleanWord = cleanWord.substring(0, wordLength - 1); } return cleanWord; } public static boolean isPunctuation(Character c) { boolean isPunctuation = false; String[] punctuationList = PUNCTUATION.split(""); String d = c.toString(); for (String punctuation : punctuationList) { if (d.equals(punctuation)) { isPunctuation = true; } } return isPunctuation; }