public final class StringBuilders extends Static
StringBuilder
instances. Some methods defined in this
class duplicate the functionalities provided in the CharSequences
class, but
modify directly the content of the provided StringBuilder
instead than creating
new objects.
CharSequences
Defined in the sis-utility
module
Modifier and Type | Method and Description |
---|---|
static void |
remove(StringBuilder buffer,
String toSearch)
Removes every occurrences of the given string in the given buffer.
|
static void |
repeat(StringBuilder buffer,
int offset,
char c,
int count)
Inserts the given character n time at the given position.
|
static void |
replace(StringBuilder buffer,
char toSearch,
char replaceBy)
Replaces every occurrences of the given character in the given buffer.
|
static void |
replace(StringBuilder buffer,
int start,
int end,
char[] chars)
Replaces the characters in a substring of the buffer with characters in the specified array.
|
static void |
replace(StringBuilder buffer,
String toSearch,
String replaceBy)
Replaces every occurrences of the given string in the given buffer.
|
static void |
toASCII(StringBuilder buffer)
Replaces some Unicode characters by ASCII characters on a "best effort basis".
|
static void |
trimFractionalPart(StringBuilder buffer)
Trims the fractional part of the given formatted number, provided that it doesn't change
the value.
|
public static void replace(StringBuilder buffer, char toSearch, char replaceBy)
buffer
- the string in which to perform the replacements.toSearch
- the character to replace.replaceBy
- the replacement for the searched character.NullArgumentException
- if the buffer
arguments is null.String.replace(char, char)
public static void replace(StringBuilder buffer, String toSearch, String replaceBy)
StringBuilder.replace(int, int, String)
for each occurrence of search
found in the buffer.buffer
- the string in which to perform the replacements.toSearch
- the string to replace.replaceBy
- the replacement for the searched string.NullArgumentException
- if any of the arguments is null.IllegalArgumentException
- if the toSearch
argument is empty.String.replace(char, char)
,
CharSequences.replace(CharSequence, CharSequence, CharSequence)
,
StringBuilder.replace(int, int, String)
public static void replace(StringBuilder buffer, int start, int end, char[] chars)
start
and extends to the
character at index end - 1
.buffer
- the buffer in which to perform the replacement.start
- the beginning index in the buffer
, inclusive.end
- the ending index in the buffer
, exclusive.chars
- the array that will replace previous contents.NullArgumentException
- if the buffer
or chars
argument is null.StringBuilder.replace(int, int, String)
public static void remove(StringBuilder buffer, String toSearch)
StringBuilder.delete(int, int)
for each occurrence of search
found in
the buffer.buffer
- the string in which to perform the removals.toSearch
- the string to remove.NullPointerException
- if any of the arguments is null.IllegalArgumentException
- if the toSearch
argument is empty.StringBuilder.delete(int, int)
public static void repeat(StringBuilder buffer, int offset, char c, int count)
count
is zero.buffer
- the buffer where to insert the character.offset
- position where to insert the characters.c
- the character to repeat.count
- number of time to repeat the given character.NullPointerException
- if the given buffer is null.IndexOutOfBoundsException
- if the given index is invalid.IllegalArgumentException
- if the given count is negative.public static void trimFractionalPart(StringBuilder buffer)
Double.toString(double)
method.
More specifically if the given buffer ends with a '.'
character followed by a
sequence of '0'
characters, then those characters are removed. Otherwise this
method does nothing. This is a "all or nothing" method: either the fractional
part is completely removed, or either it is left unchanged.
buffer
- the buffer to trim if possible.NullArgumentException
- if the given buffer
is null.CharSequences.trimFractionalPart(CharSequence)
public static void toASCII(StringBuilder buffer)
buffer
- the text to scan for Unicode characters to replace by ASCII characters.NullArgumentException
- if the given buffer
is null.CharSequences.toASCII(CharSequence)
,
Normalizer.normalize(CharSequence, Normalizer.Form)
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.