Package io.microsphere.text
Class FormatUtils
- java.lang.Object
-
- io.microsphere.text.FormatUtils
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_PLACEHOLDER
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
format(java.lang.String pattern, java.lang.Object... args)
Formats the givenpattern
by replacing all occurrences of the default placeholder (DEFAULT_PLACEHOLDER
) with corresponding values from the provided arguments.static java.lang.String
formatWithPlaceholder(java.lang.String pattern, java.lang.String placeholder, java.lang.Object... args)
Formats the givenpattern
by replacing all occurrences of the specified placeholder with corresponding values from the provided arguments.
-
-
-
Field Detail
-
DEFAULT_PLACEHOLDER
public static final java.lang.String DEFAULT_PLACEHOLDER
- See Also:
- Constant Field Values
-
-
Method Detail
-
format
public static java.lang.String format(java.lang.String pattern, java.lang.Object... args)
Formats the givenpattern
by replacing all occurrences of the default placeholder (DEFAULT_PLACEHOLDER
) with corresponding values from the provided arguments.If there are more placeholders in the pattern than arguments provided, extra placeholders will remain unchanged.
Example Usage
format("Hello, {}", "World") => "Hello, World" format("{} + {} = 4", 2, 2) => "2 + 2 = 4" format("No replacement here", "extra") => "No replacement here"
- Parameters:
pattern
- the string pattern to be formattedargs
- the arguments to replace the placeholders in the pattern- Returns:
- the formatted string, with placeholders replaced by corresponding argument values
-
formatWithPlaceholder
public static java.lang.String formatWithPlaceholder(java.lang.String pattern, java.lang.String placeholder, java.lang.Object... args)
Formats the givenpattern
by replacing all occurrences of the specified placeholder with corresponding values from the provided arguments.If there are more placeholders in the pattern than arguments provided, extra placeholders will remain unchanged.
Example Usage
formatWithPlaceholder("Hello, [placeholder]", "[placeholder]", "World") => "Hello, World" formatWithPlaceholder("[placeholder] + [placeholder] = 4", "[placeholder]", 2, 2) => "2 + 2 = 4" formatWithPlaceholder("No replacement here", "[placeholder]", "extra") => "No replacement here"
- Parameters:
pattern
- the string pattern to be formattedplaceholder
- the placeholder string to be replacedargs
- the arguments to replace the placeholders in the pattern- Returns:
- the formatted string, with placeholders replaced by corresponding argument values
-
-