java.lang.Object
org.klojang.util.StringMethods
Methods for working with strings. Quite a few methods in this class are geared
towards printing. They take an argument of type
Object
, rather than
String
. If the argument is null
, they will return an empty string,
else they will call toString()
on the argument and then manipulate the
resulting String
. They are null-safe and they will never return
null
themselves. The parameter name for the Object
argument will
be "input". For ease of reading the input
parameter will still be referred
to as a String
.-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilder
append
(StringBuilder sb, Object val) Appends the specified value to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
append
(StringBuilder sb, Object val0, Object val1) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
append
(StringBuilder sb, Object val0, Object val1, Object val2) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
append
(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
append
(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
append
(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6, Object val7) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
append
(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6, Object val7, Object val8) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static StringBuilder
append
(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6, Object val7, Object val8, Object val9, Object... moreData) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.static String
Concatenates the specified data.static int
Counts the number of occurrences ofsubstr
withininput
.static int
Counts the number of occurrences ofsubstr
withininput
.static int
Counts the number of occurrences ofsubstr
withininput
.static int
countDiscrete
(Object input, String substr) Counts the number of non-overlapping occurrences ofsubstr
withininput
.static int
countDiscrete
(Object input, String substr, boolean ignoreCase) Counts the number of non-overlapping occurrences ofsubstr
withininput
.static int
countDiscrete
(Object input, String substr, boolean ignoreCase, int limit) Counts the number of non-overlapping occurrences ofsubstr
withininput
.static String
Returnsinput.toString()
if its length does not exceedmaxWidth
, else truncates the string and appends "...", such that the new string's length does not exceedmaxWidth
.Determines whetherinput
ends with any of the specified suffixes.endsWith
(Object input, boolean ignoreCase, Collection<String> suffixes) Determines whetherinput
ends with any of the specified suffixes.static String
ensurePrefix
(Object input, String prefix) Prefixes to specified prefix toinput
if it did not already start with that prefix.static String
ensureSuffix
(Object input, String suffix) Appends to specified suffix toinput
if it did not already have that suffix.static String
firstToLower
(Object input) Ensures that the first character of the specified string is not an uppercase character.static String
firstToUpper
(Object input) Ensures that the first character of the specified string is not a lowercase character.static int[]
getLineAndColumn
(String str, int index) Returns the line number and column number of the character at the specified index, given the system-defined line separator.static int[]
getLineAndColumn
(String str, int index, String lineSep) Returns the line number and column number of the character at the specified index, given the specified line separator.static String
Returns the 1st argument if it is not a whitespace-only string, else the 2nd argument.static int
Returns the index of the nth occurrence of the specified substring withininput
.static boolean
Whether the specified string is null or blank.static String
Removes all occurrences of the specified prefixes from the start of a string.static String
Removes all occurrences of the specified prefixes from the start of a string.static String
Left-pads a string to the specified width using the space character (' ').static String
Left-pads a string to the specified width using the specified padding character.static String
Left-pads a string to the specified width using the specified padding character and then appends the specified terminator.static String
Left-trims all characters contained inchars
from the specified string.static String
Centers (left- and right-pads) a string within the specified width using the space character.static String
Centers (left- and right-pads) a string within the specified width using the specified padding character.static String
Centers (left- and right-pads) a string within the specified width using the specified padding character and then appends the specified delimiter.static String
Removes all occurrences of the specified suffixes from the end of a string.static String
Removes all occurrences of the specified suffixes from the end of a string.static String
Right-pads a string to the specified width using the space character (' ').static String
Right-pads a string to the specified width using the specified padding character.static String
Right-pads a string to the specified width using the specified padding character and appends the specified suffix.static String
Right-trims all characters contained inchars
from the specified string.startsWith
(Object input, boolean ignoreCase, String... prefixes) Determines whetherinput
starts with any of the specified prefixes.startsWith
(Object input, boolean ignoreCase, Collection<String> prefixes) Determines whetherinput
starts with any of the specified prefixes.static String
Substring method that facilitates substring retrieval relative to the end of a string.static String
Substring method that facilitates substring retrieval relative to the end of a string as well as substring retrieval in the opposite direction.static String
substrAfter
(Object input, String substr, int occurrence) Returns the substring after the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring.static String
substrFrom
(Object input, String substr, int occurrence) Returns the substring from (and including) the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring.static String
substringBefore
(Object input, String substr, int occurrence) Returns the substring up to, but not including the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring.static String
substringOnTo
(Object input, String substr, int occurrence) Returns the substring up to, and including the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring.static String
toShortString
(Object obj) Returns a short string representation of an object.static String
toShortString
(Object obj, int maxWidth) Returns a short string representation of an object.static String
toShortString
(Object obj, int maxWidth, int maxElements, int maxEntries) Returns a short string representation of an object.static String
Left and right-trims the specified string.
-
Field Details
-
EMPTY_STRING
The empty string.- See Also:
-
-
Method Details
-
append
Appends the specified value to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the value toval
- The value to append- Returns:
- the
StringBuilder
-
append
Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another value- Returns:
- the
StringBuilder
-
append
Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another value- Returns:
- the
StringBuilder
-
append
public static StringBuilder append(StringBuilder sb, Object val0, Object val1, Object val2, Object val3) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another valueval3
- another value- Returns:
- the
StringBuilder
-
append
public static StringBuilder append(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another valueval3
- another valueval4
- another value- Returns:
- the
StringBuilder
-
append
public static StringBuilder append(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another valueval3
- another valueval4
- another valueval5
- another value- Returns:
- the
StringBuilder
-
append
public static StringBuilder append(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another valueval3
- another valueval4
- another valueval5
- another valueval6
- another value- Returns:
- the
StringBuilder
-
append
public static StringBuilder append(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6, Object val7) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another valueval3
- another valueval4
- another valueval5
- another valueval6
- another valueval7
- another value- Returns:
- the
StringBuilder
-
append
public static StringBuilder append(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6, Object val7, Object val8) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another valueval3
- another valueval4
- another valueval5
- another valueval6
- another valueval7
- another valueval8
- another value- Returns:
- the
StringBuilder
-
append
public static StringBuilder append(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6, Object val7, Object val8, Object val9, Object... moreData) Appends the specified values to the specifiedStringBuilder
and returns theStringBuilder
.- Parameters:
sb
- theStringBuilder
to append the values toval0
- a valueval1
- another valueval2
- another valueval3
- another valueval4
- another valueval5
- another valueval6
- another valueval7
- another valueval8
- another valueval9
- another valuemoreData
- more values- Returns:
- the
StringBuilder
-
concat
Concatenates the specified data.- Parameters:
data
- the data to append (must not be null)- Returns:
- the concatenation of the data
-
count
Counts the number of occurrences ofsubstr
withininput
. Returns 0 (zero) ifinput
isnull
.- Parameters:
input
- the string to searchsubstr
- the substring to search for (must not benull
or empty)- Returns:
- the number of occurrences of
substr
withininput
-
count
Counts the number of occurrences ofsubstr
withininput
. Returns 0 (zero) ifinput
isnull
.- Parameters:
input
- the string to searchsubstr
- the substring to search for (must not benull
or empty)ignoreCase
- whether to ignore case while comparing substrings- Returns:
- the number of occurrences of
substr
withininput
-
count
Counts the number of occurrences ofsubstr
withininput
. Returns 0 (zero) ifinput
isnull
.- Parameters:
input
- the string to searchsubstr
- the substring to search for (must not benull
or empty)ignoreCase
- whether to ignore case while comparing substringslimit
- the maximum number of occurrences the count. You may specify 0 (zero) for "no maximum".- Returns:
- the number of occurrences of
substr
withininput
(will not exceedlimit
)
-
countDiscrete
Counts the number of non-overlapping occurrences ofsubstr
withininput
. The string to search for must not be null or empty and is not treated as a regular expression. Returns 0 (zero) ifinput
isnull
.- Parameters:
input
- the string to searchsubstr
- the substring to search for- Returns:
- the number of non-overlapping occurrences of
substr
withininput
-
countDiscrete
Counts the number of non-overlapping occurrences ofsubstr
withininput
. The string to search for must not be null or empty and is not treated as a regular expression. Returns 0 (zero) ifinput
isnull
.- Parameters:
input
- the string to searchsubstr
- the substring to search forignoreCase
- whether to ignore case while comparing substrings- Returns:
- the number of non-overlapping occurrences of
substr
withininput
-
countDiscrete
Counts the number of non-overlapping occurrences ofsubstr
withininput
. Returns 0 (zero) ifinput
isnull
.- Parameters:
input
- the string to searchsubstr
- the substring to search forignoreCase
- whether to ignore case while comparing substringslimit
- the maximum number of occurrences the count. You may specify 0 (zero) for "no maximum".- Returns:
- the number of non-overlapping occurrences of
substr
withininput
(will not exceedlimit
)
-
ellipsis
Returnsinput.toString()
if its length does not exceedmaxWidth
, else truncates the string and appends "...", such that the new string's length does not exceedmaxWidth
. The lower bound formaxWidth
will tacitly be clamped to 4, so that at least one letter of the string is displayed.Examples:
String hello = "Hello World, how are you?"; assertEquals("Hello W...", ellipsis(hello, 10)); assertEquals("H...", ellipsis(hello, 4)); assertEquals(hello, ellipsis(hello, 100));
- Parameters:
input
- the string to abbreviate, if necessarymaxWidth
- the maximum width of the string (must be greater than 3)- Returns:
- the string itself or an abbreviated version, suffixed with "..."
-
toShortString
Returns a short string representation of an object. Equivalent totoShortString(obj, 50)
.- Parameters:
obj
- the object to stringify- Returns:
- a string consisting of no more than 50 characters
-
toShortString
Returns a short string representation of an object. Roughly equivalent totoShortString(obj, maxWidth, maxWidth/8, maxWidth/16)
.- Parameters:
obj
- the object to stringifymaxWidth
- the maximum width of the returned string- Returns:
- a string whose length will not exceed
maxWidth
-
toShortString
Returns a short string representation of an object. Broadly speaking, this method behaves as follows:- if
obj
isnull
, it is stringified to "null". - if
obj
is aClass
object, it is stringified usingClassMethods.simpleClassName
. - if
obj
is aCollection
, it is stringified as though by callingtoString()
on the collection after all but the firstmaxElements
elements have been removed from it. (This prevents collections from blowing up into huge strings, only for them to be truncated tomaxWidth
again. So there is both a performance aspect and a security aspect to making the maximum number of elements user-definable.) - if
obj
is an array, it is stringified as though by callingArrays.deepToString
on it after all but the firstmaxElements
elements have been removed from it. - if
obj
is aMap
, it is stringified as though by callingtoString()
on the collection after all but the firstmaxEntries
entries have been removed from it. - Otherwise
obj
is stringified simply by callingtoString
on it.
The resulting string is then truncated to
maxWidth
as though by callingellipsis
on it.You should not rely on the exact appearance of the returned string. Future implementations may produce slightly different strings for the same object. (For example, they might give special treatment to certain other types of objects.) The only stated aim of this method is to provide a length-constrained string representation of an object. The exact contents of the returned string is unspecified.
- Parameters:
obj
- the object to stringifymaxWidth
- the maximum width of the returned stringmaxElements
- the maximum number of elements to process if the argument is an array orCollection
.maxEntries
- the maximum number of entries to process if the argument is aMap
.- Returns:
- a string whose length will not exceed
maxWidth
- if
-
startsWith
public static Optional<String> startsWith(Object input, boolean ignoreCase, Collection<String> prefixes) Determines whetherinput
starts with any of the specified prefixes. Returns anOptional
containing the first prefix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified prefixes.- Parameters:
input
- the string to testignoreCase
- whether to ignore caseprefixes
- the prefixes to test- Returns:
- Returns an
Optional
containing the first prefix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified prefixes.
-
startsWith
Determines whetherinput
starts with any of the specified prefixes. Returns anOptional
containing the first prefix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified prefixes.- Parameters:
input
- the string to testignoreCase
- whether to ignore caseprefixes
- the prefixes to test- Returns:
- Returns an
Optional
containing the first prefix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified prefixes.
-
endsWith
public static Optional<String> endsWith(Object input, boolean ignoreCase, Collection<String> suffixes) Determines whetherinput
ends with any of the specified suffixes. Returns anOptional
containing the first suffix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified suffixes.- Parameters:
input
- the string to testignoreCase
- whether to ignore casesuffixes
- the suffixes to test- Returns:
- Returns an
Optional
containing the first suffix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified suffixes.
-
endsWith
Determines whetherinput
ends with any of the specified suffixes. Returns anOptional
containing the first suffix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified suffixes.- Parameters:
input
- the string to testignoreCase
- whether to ignore casesuffixes
- the suffixes to test- Returns:
- Returns an
Optional
containing the first suffix found to be equal to the end of the string, or an emptyOptional
if the string does not end with any of the specified suffixes.
-
ensurePrefix
Prefixes to specified prefix toinput
if it did not already start with that prefix. Returnsprefix
ifinput
is null,- Parameters:
input
- theString
to which to append the prefixprefix
- the prefix (must not benull
)- Returns:
- a string that is guaranteed to start with
prefix
-
ensureSuffix
Appends to specified suffix toinput
if it did not already have that suffix. Ifinput
is null,suffix
is returned.- Parameters:
input
- theString
to which to append the suffixsuffix
- the suffix (must not benull
)- Returns:
- a string that is guaranteed to end with
suffix
-
isBlank
Whether the specified string is null or blank.- Parameters:
input
- the string- Returns:
- whether it is null or blank
-
ifBlank
Returns the 1st argument if it is not a whitespace-only string, else the 2nd argument.- Parameters:
input
- the string to return if not nulldfault
- the replacement string- See Also:
-
lchop
Removes all occurrences of the specified prefixes from the start of a string. The returned string will no longer start with any of the specified prefixes.- Parameters:
input
- the string to remove the prefixes fromprefixes
- the prefixes to remove
-
lchop
Removes all occurrences of the specified prefixes from the start of a string. The returned string will no longer start with any of the specified prefixes.- Parameters:
input
- the string to remove the prefixes fromignoreCase
- whether to ignore caseprefixes
- the prefixes to remove
-
rchop
Removes all occurrences of the specified suffixes from the end of a string. The returned string will no longer end with any of the specified suffixes.- Parameters:
input
- the string to manipulatesuffixes
- the suffixes to chop off the right of the string- Returns:
- a String that does not end with any of the specified suffixes
-
rchop
Removes all occurrences of the specified suffixes from the end of a string. The returned string will no longer end with any of the specified suffixes.- Parameters:
input
- the string to manipulateignoreCase
- whether to ignore case while chopping off suffixessuffixes
- a String that does not end with any of the specified suffixes
-
firstToUpper
Ensures that the first character of the specified string is not a lowercase character.- Parameters:
input
- the string- Returns:
- the same string except that the first character is not a lowercase character
-
firstToLower
Ensures that the first character of the specified string is not an uppercase character.- Parameters:
input
- the string- Returns:
- the same string except that the first character is not an uppercase character
-
lpad
Left-pads a string to the specified width using the space character (' ').- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is returned without padding.- Returns:
- the left-padded string
-
lpad
Left-pads a string to the specified width using the specified padding character.- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is returned without padding.padChar
- the character used to left-pad the string- Returns:
- the left-padded string
-
lpad
Left-pads a string to the specified width using the specified padding character and then appends the specified terminator.- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is returned without padding.padChar
- the character used to left-pad the stringdelimiter
- a delimiter to append to the padded string. Specify null or an empty string to indicate that no delimiter should be appended.- Returns:
- the left-padded string
- Throws:
IllegalArgumentException
- Ifterminator
is null
-
pad
Centers (left- and right-pads) a string within the specified width using the space character.- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is printed without padding.- Returns:
- the left- and right-padded string plus the terminator
-
pad
Centers (left- and right-pads) a string within the specified width using the specified padding character.- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is printed without padding.padChar
- the character used to left- and right-pad the string.- Returns:
- the left- and right-padded string plus the terminator
-
pad
Centers (left- and right-pads) a string within the specified width using the specified padding character and then appends the specified delimiter.- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is printed without padding.padChar
- the character used to left- and right-pad the string.delimiter
- a delimiter to append to the padded string. Specify null or an empty string to indicate that no delimiter should be appended.- Returns:
- the left- and right-padded string plus the terminator
-
rpad
Right-pads a string to the specified width using the space character (' ').- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is returned without padding.- Returns:
- the right-padded string
-
rpad
Right-pads a string to the specified width using the specified padding character.- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is returned without padding.padChar
- the character used to left-pad the string.- Returns:
- the right-padded string
-
rpad
Right-pads a string to the specified width using the specified padding character and appends the specified suffix.- Parameters:
input
- an object whosetoString()
method produces the string to be padded. Null is treated as the empty string.width
- the total length of the padded string. If the string itself is wider than the specified width, the string is printed without padding.padChar
- the character used to right-pad the string.suffix
- A suffix to append to the padded string.- Returns:
- the right-padded string
-
ltrim
Left-trims all characters contained inchars
from the specified string. The resulting string will not start with any of the characters contained inchars
.- Parameters:
input
- theString
to trimchars
- the character to trim off theString
- Returns:
- the left-trimmed
String
or the input string if it did not start with any of the specified characters
-
rtrim
Right-trims all characters contained inchars
from the specified string. The resulting string will not end with any of the characters contained inchars
.- Parameters:
input
- theString
to trimchars
- the character to trim off theString
(must not benull
or empty)- Returns:
- the right-trimmed
String
or the input string if it did not end with any of the specified characters
-
trim
Left and right-trims the specified string. The resulting string will neither start nor end with any of the specified characters.- Parameters:
input
- theString
to trimchars
- the character to trim off theString
(must not benull
or empty)- Returns:
- the trimmed
String
.
-
substr
Substring method that facilitates substring retrieval relative to the end of a string. Iffrom
is negative, it is taken relative to the end of the string (-1
being equivalent tostr.length()-1
).- Parameters:
str
- theString
to extract a substring fromfrom
- the start index withinstring
(may be negative)- Returns:
- the substring
-
substr
Substring method that facilitates substring retrieval relative to the end of a string as well as substring retrieval in the opposite direction. Iffrom
is negative, it is taken relative to the end of the string (-1
being equivalent tostr.length()-1
). Iflength
is negative, the substring is taken in the opposite direction. The character atfrom
will then be the last character of the substring.- Parameters:
str
- theString
to extract a substring from. Must not be null.from
- the start index withinstring
(may be negative)length
- the desired length of the substring- Returns:
- the substring
- See Also:
-
indexOf
Returns the index of the nth occurrence of the specified substring withininput
. To find the first occurrence of the specified substring, specify 1 foroccurrence
; to find the second occurrence, specify 2, etc. Ifinput
isnull
, or if there is no nth occurrence of the specified substring, the return value will be -1. You can specify a negative occurrence to search backwards from the end of the string. Specify -1 for the last occurrence of the specified substring; -2 for the last-but-one occurrence, etc.- Parameters:
input
- the string to searchsubstr
- the substring to search for (must not be null or empty)occurrence
- the occurrence number of the substring (1 means: get index of 1st occurrence; -1 means: get index of last occurrence)- Returns:
- the index of the nth occurrence of the specified substring
-
substringBefore
Returns the substring up to, but not including the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring. Returns an empty string ifinput
isnull
. Specify 1 to find the first occurrence of the substring; 2 to find the second occurrence, etc. Specify -1 to find the first occurrence; -2 to find the last-but-one occurrence, etc.- Parameters:
input
- the string to searchsubstr
- the substring to search foroccurrence
- the occurrence number of the substring. Specify 1 for first occurrence; 2 for second occurrence, etc. Specify -1 for last occurrence, -2 for last-but-one occurrence, etc.- Returns:
- a substring up to (not including) the nth occurrence of the specified substring
-
substringOnTo
Returns the substring up to, and including the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring. Returns an empty string ifinput
isnull
. Specify 1 to find the first occurrence of the substring; 2 to find the second occurrence, etc. Specify -1 to find the first occurrence; -2 to find the last-but-one occurrence, etc.- Parameters:
input
- the string to searchsubstr
- the substring to search foroccurrence
- the occurrence number of the substring. Specify 1 for first occurrence; 2 for second occurrence, etc. Specify -1 for last occurrence, -2 for last-but-one occurrence, etc.- Returns:
- a substring up to, and including the nth occurrence of the specified substring
-
substrFrom
Returns the substring from (and including) the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring. Returns an empty string ifinput
isnull
. Specify 1 to find the first occurrence of the substring; 2 to find the second occurrence, etc. Specify -1 to find the first occurrence; -2 to find the last-but-one occurrence, etc.- Parameters:
input
- the string to searchsubstr
- the substring to search foroccurrence
- the occurrence number of the substring. Specify 1 for first occurrence; 2 for second occurrence, etc. Specify -1 for last occurrence, -2 for last-but-one occurrence, etc.- Returns:
- a substring from (inclusive) the nth occurrence of the specified substring
-
substrAfter
Returns the substring after the nth occurrence of the specified substring, or the entire string if there is no nth occurrence of the substring. Returns an empty string ifinput
isnull
. Specify 1 to find the first occurrence of the substring; 2 to find the second occurrence, etc. Specify -1 to find the first occurrence; -2 to find the last-but-one occurrence, etc.- Parameters:
input
- the string to searchsubstr
- the substring to search foroccurrence
- the occurrence number of the substring. Specify 1 for first occurrence; 2 for second occurrence, etc. Specify -1 for last occurrence, -2 for last-but-one occurrence, etc.- Returns:
- a substring after (not including) the nth occurrence of the specified substring
-
getLineAndColumn
Returns the line number and column number of the character at the specified index, given the system-defined line separator.- Parameters:
str
- the string to searchindex
- the string index to determine the line and column number of- Returns:
- a two-element array containing the line number and column number of the character at the specified index
-
getLineAndColumn
Returns the line number and column number of the character at the specified index, given the specified line separator.- Parameters:
str
- the string to searchindex
- the string index to determine the line and column number oflineSep
- the line separator- Returns:
- a two-element array containing the line number and column number of the character at the specified index
-