Class WordReplacer


  • public class WordReplacer
    extends Object
    • Constructor Detail

      • WordReplacer

        public WordReplacer()
    • Method Detail

      • replaceWords

        public static String replaceWords​(String input,
                                          String[] words,
                                          String[] replaces)
        Replace all words in the input by the replaces. The replacements happens only if the texts to replace are not part of a greater word, that is, if the text is a whole word, separated by non Character.isLetterOrDigit(char) characters.
        Parameters:
        input - the text where the replacements take place
        words - the words to look for and replace
        replaces - the new words to use
      • replaceWordsIgnoreCase

        public static String replaceWordsIgnoreCase​(String input,
                                                    String[] words,
                                                    String[] replaces)
        Replace all words in the input by the replaces. The replacements happens only if the texts to replace are not part of a greater word, that is, if the text is a whole word, separated by non Character.isLetterOrDigit(char) characters.
        Parameters:
        input - the text where the replacements take place
        words - the words to look for and replace
        replaces - the new words to use
      • replaceWord

        public static String replaceWord​(String input,
                                         String word,
                                         String replace)
        Replace all occurrences of word by replace in the input. The replacement happens only if the word to replace is separated from others words, that is, it's not part of a word. The implementation is that the previous and next characters of the word must be a Character.isLetterOrDigit(char) char.
        Parameters:
        input - text where the replacements take place
        word - the word to replace
        replace - the new text to use
      • replaceWordIgnoreCase

        public static String replaceWordIgnoreCase​(String input,
                                                   String word,
                                                   String replace)
        Replace all occurrences of word by replace in the input. The replacement happens only if the word to replace is separated from others words, that is, it's not part of a word. The implementation is that the previous and next characters of the word must be a Character.isLetterOrDigit(char) char.
        Parameters:
        input - text where the replacements take place
        word - the word to replace
        replace - the new text to use
      • replaceWord

        public static void replaceWord​(StringBuilder input,
                                       String word,
                                       String replace)
        Replace all occurrences of word by replace in the input. The replacement happens only if the word to replace is separated from others words, that is, it's not part of a word. The implementation is that the previous and next characters of the word must be a Character.isLetterOrDigit(char) char.
        Parameters:
        input - text where the replacements take place
        word - the word to replace
        replace - the new text to use