Class StringMethods
java.lang.Object
org.klojang.util.StringMethods
Methods for working with strings. Many 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
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilderappend(StringBuilder sb, Object val) Appends the specified value to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderappend(StringBuilder sb, Object val0, Object val1) Appends the specified values to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderappend(StringBuilder sb, Object val0, Object val1, Object val2) Appends the specified values to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderAppends the specified values to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderAppends the specified values to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderappend(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5) Appends the specified values to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderappend(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6) Appends the specified values to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderappend(StringBuilder sb, Object val0, Object val1, Object val2, Object val3, Object val4, Object val5, Object val6, Object val7) Appends the specified values to the specifiedStringBuilderand returns theStringBuilder.static StringBuilderappend(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 specifiedStringBuilderand returns theStringBuilder.static StringBuilderappend(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 specifiedStringBuilderand returns theStringBuilder.static StringConcatenates the specified data.static intCounts the number of occurrences ofsubstrwithininput.static intCounts the number of occurrences ofsubstrwithininput.static intCounts the number of occurrences ofsubstrwithininput.static intcountDiscrete(Object input, String substr) Counts the number of non-overlapping occurrences ofsubstrwithininput.static intcountDiscrete(Object input, String substr, boolean ignoreCase) Counts the number of non-overlapping occurrences ofsubstrwithininput.static intcountDiscrete(Object input, String substr, boolean ignoreCase, int limit) Counts the number of non-overlapping occurrences ofsubstrwithininput.static StringReturnsinput.toString()if its length does not exceedmaxWidth, else truncates the string and appends "...", such that the new string's length does not exceedmaxWidth.Determines whetherinputends with any of the specified suffixes.endsWith(Object input, boolean ignoreCase, Collection<String> suffixes) Determines whetherinputends with any of the specified suffixes.static StringensurePrefix(Object input, String prefix) Prefixes to specified prefix toinputif it did not already start with that prefix.static StringensureSuffix(Object input, String suffix) Appends to specified suffix toinputif it did not already have that suffix.static StringfirstToLower(Object input) Ensures that the first character of the specified string is not an uppercase character.static StringfirstToUpper(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 StringReturns the 1st argument if it is not a whitespace-only string, else the 2nd argument.static intReturns the index of the nth occurrence of the specified substring withininput.static booleanWhether the specified string is null or blank.static StringRemoves all occurrences of the specified prefixes from the start of a string.static StringRemoves all occurrences of the specified prefixes from the start of a string.static StringLeft-pads a string to the specified width using the space character (' ').static StringLeft-pads a string to the specified width using the specified padding character.static StringLeft-pads a string to the specified width using the specified padding character and then appends the specified terminator.static StringLeft-trims all characters contained incharsfrom the specified string.static StringCenters (left- and right-pads) a string within the specified width using the space character.static StringCenters (left- and right-pads) a string within the specified width using the specified padding character.static StringCenters (left- and right-pads) a string within the specified width using the specified padding character and then appends the specified delimiter.static StringRemoves all occurrences of the specified suffixes from the end of a string.static StringRemoves all occurrences of the specified suffixes from the end of a string.static StringRight-pads a string to the specified width using the space character (' ').static StringRight-pads a string to the specified width using the specified padding character.static StringRight-pads a string to the specified width using the specified padding character and appends the specified suffix.static StringRight-trims all characters contained incharsfrom the specified string.startsWith(Object input, boolean ignoreCase, String... prefixes) Determines whetherinputstarts with any of the specified prefixes.startsWith(Object input, boolean ignoreCase, Collection<String> prefixes) Determines whetherinputstarts with any of the specified prefixes.static StringSubstring method that facilitates substring retrieval relative to the end of a string.static StringSubstring method that facilitates substring retrieval relative to the end of a string as well as substring retrieval in the opposite direction.static StringsubstringAfter(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 StringsubstringBefore(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 StringsubstringFrom(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 StringsubstringOnTo(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 StringtoShortString(Object obj) Returns a short string representation of an object.static StringtoShortString(Object obj, int maxWidth) Returns a short string representation of an object.static StringtoShortString(Object obj, int maxWidth, int maxElements, int maxEntries) Returns a short string representation of an object.static StringLeft and right-trims the specified string.
-
Field Details
-
EMPTY_STRING
-
-
Method Details
-
append
Appends the specified value to the specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto append the value toval- The value to append- Returns:
- the
StringBuilder
-
append
Appends the specified values to the specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto append the values toval0- a valueval1- another value- Returns:
- the
StringBuilder
-
append
Appends the specified values to the specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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 specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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 specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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 specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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 specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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 specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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 specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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 specifiedStringBuilderand returns theStringBuilder.- Parameters:
sb- theStringBuilderto 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
-
count
Counts the number of occurrences ofsubstrwithininput. Returns 0 (zero) ifinputisnull.- Parameters:
input- the string to searchsubstr- the substring to search for (must not benullor empty)- Returns:
- the number of occurrences of
substrwithininput
-
count
Counts the number of occurrences ofsubstrwithininput. Returns 0 (zero) ifinputisnull.- Parameters:
input- the string to searchsubstr- the substring to search for (must not benullor empty)ignoreCase- whether to ignore case while comparing substrings- Returns:
- the number of occurrences of
substrwithininput
-
count
Counts the number of occurrences ofsubstrwithininput. Returns 0 (zero) ifinputisnull.- Parameters:
input- the string to searchsubstr- the substring to search for (must not benullor 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
substrwithininput(will not exceedlimit)
-
countDiscrete
Counts the number of non-overlapping occurrences ofsubstrwithininput. The string to search for must not be null or empty and is not treated as a regular expression. Returns 0 (zero) ifinputisnull.- Parameters:
input- the string to searchsubstr- the substring to search for- Returns:
- the number of non-overlapping occurrences of
substrwithininput
-
countDiscrete
Counts the number of non-overlapping occurrences ofsubstrwithininput. The string to search for must not be null or empty and is not treated as a regular expression. Returns 0 (zero) ifinputisnull.- 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
substrwithininput
-
countDiscrete
Counts the number of non-overlapping occurrences ofsubstrwithininput. Returns 0 (zero) ifinputisnull.- 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
substrwithininput(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 formaxWidthwill 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
objisnull, it is stringified to "null". - if
objis aClassobject, it is stringified usingClassMethods.simpleClassName. - if
objis aCollection, it is stringified as though by callingtoString()on the collection after all but the firstmaxElementselements have been removed from it. (This prevents collections from blowing up into huge strings, only for them to be truncated tomaxWidthagain. So there is both a performance aspect and a security aspect to making the maximum number of elements user-definable.) - if
objis an array, it is stringified as though by callingArrays.deepToStringon it after all but the firstmaxElementselements have been removed from it. - if
objis aMap, it is stringified as though by callingtoString()on the collection after all but the firstmaxEntriesentries have been removed from it. - Otherwise
objis stringified simply by callingtoStringon it.
The resulting string is then truncated to
maxWidthas though by callingellipsison 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 whetherinputstarts with any of the specified prefixes. Returns anOptionalcontaining the first prefix found to be equal to the end of the string, or an emptyOptionalif 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
Optionalcontaining the first prefix found to be equal to the end of the string, or an emptyOptionalif the string does not end with any of the specified prefixes.
-
startsWith
Determines whetherinputstarts with any of the specified prefixes. Returns anOptionalcontaining the first prefix found to be equal to the end of the string, or an emptyOptionalif 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
Optionalcontaining the first prefix found to be equal to the end of the string, or an emptyOptionalif 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 whetherinputends with any of the specified suffixes. Returns anOptionalcontaining the first suffix found to be equal to the end of the string, or an emptyOptionalif 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
Optionalcontaining the first suffix found to be equal to the end of the string, or an emptyOptionalif the string does not end with any of the specified suffixes.
-
endsWith
Determines whetherinputends with any of the specified suffixes. Returns anOptionalcontaining the first suffix found to be equal to the end of the string, or an emptyOptionalif 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
Optionalcontaining the first suffix found to be equal to the end of the string, or an emptyOptionalif the string does not end with any of the specified suffixes.
-
ensurePrefix
Prefixes to specified prefix toinputif it did not already start with that prefix. Returnsprefixifinputis null,- Parameters:
input- theStringto 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 toinputif it did not already have that suffix. Ifinputis null,suffixis returned.- Parameters:
input- theStringto 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
-
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
-
firstToLower
-
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- Ifterminatoris 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 incharsfrom the specified string. The resulting string will not start with any of the characters contained inchars.- Parameters:
input- theStringto trimchars- the character to trim off theString- Returns:
- the left-trimmed
Stringor the input string if it did not start with any of the specified characters
-
rtrim
Right-trims all characters contained incharsfrom the specified string. The resulting string will not end with any of the characters contained inchars.- Parameters:
input- theStringto trimchars- the character to trim off theString(must not benullor empty)- Returns:
- the right-trimmed
Stringor 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- theStringto trimchars- the character to trim off theString(must not benullor empty)- Returns:
- the trimmed
String.
-
substring
Substring method that facilitates substring retrieval relative to the end of a string. Iffromis negative, it is taken relative to the end of the string (-1being equivalent tostr.length()-1).- Parameters:
str- theStringto extract a substring fromfrom- the start index withinstring(may be negative)- Returns:
- the substring
-
substring
Substring method that facilitates substring retrieval relative to the end of a string as well as substring retrieval in the opposite direction. Iffromis negative, it is taken relative to the end of the string (-1being equivalent tostr.length()-1). Iflengthis negative, the substring is taken in the opposite direction. The character atfromwill then be the last character of the substring.- Parameters:
str- theStringto 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. Ifinputisnull, 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 ifinputisnull. 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 ifinputisnull. 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
-
substringFrom
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 ifinputisnull. 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
-
substringAfter
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 ifinputisnull. 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
-