Class TextVariableHelper

java.lang.Object
com.helger.commons.text.util.TextVariableHelper

@Immutable public final class TextVariableHelper extends Object
This class provides an easy way to replace variables in a string with other values. The variables need to be present in the form of ${bla}. The variable helper supports masking with the backslash (\) character so that the "$" can be represented as "\$".
Since:
10.2.0
Author:
Philip Helger
  • Method Details

    • containsVariables

      public static boolean containsVariables(@Nullable String sSourceString)
      Quickly check if a string contains a variable.
      Parameters:
      sSourceString - the string to check for variables.
      Returns:
      true if at least one variable is contained, false if not.
    • forEachTextAndVariable

      public static void forEachTextAndVariable(@Nullable String sSourceString, @Nonnull Consumer<String> aTextFragmentHandler, @Nonnull Consumer<String> aVariableNameHandler)
      Parse the provided source string looking for variables in the form ${...} and invoke callbacks for either text fragments or variable names.
      Parameters:
      sSourceString - The source string to parse and analyze. May be null.
      aTextFragmentHandler - The callback to be invoked for each text fragment. May not be null.
      aVariableNameHandler - The callback to be invoked for each variable name. May not be null.
    • getWithReplacedVariables

      @Nullable public static String getWithReplacedVariables(@Nullable String sSourceString, @Nonnull UnaryOperator<String> aVariableProvider)