Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-893

Default value for StrSubstitutor

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 3.2
    • Component/s: lang.text.*
    • Labels:
      None

      Description

      public static void main(String[] args) {
      String s = "The number of ${item} items currently available: ${number}";
      String result = StrSubstitutor.replace(s, Collections.singletonMap("item", "monitor"));
      System.out.println(result);
      }

      This results in: "The number of monitor items currently available: ${number}".

      I'd need a default value for a placeholder that cannot be resolved.

      String result = StrSubstitutor.replace(s, Collections.singletonMap("item", "monitor"), "N/A");

      -> "The number of monitor items currently available: N/A".

        Attachments

        1. StrSubstitutorTest.java
          26 kB
          Woonsan Ko
        2. StrSubstitutor.java
          49 kB
          Woonsan Ko
        3. default-value-operation-new.patch
          22 kB
          Woonsan Ko
        4. default-value-operation.patch
          23 kB
          Woonsan Ko

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              lauri.siltanen Lauri Siltanen
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: