LocalSolver logo
is now
Hexaly logo

We're excited to share that we are moving forward. We're leaving behind the LocalSolver brand and transitioning to our new identity: Hexaly. This represents a leap forward in our mission to enable every organization to make better decisions faster when faced with operational and strategic challenges.

This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

String module

This module contains types and functions to manipulate and build strings.

type string

This is the base type for strings. String objects can only contain 8-bit characters. UTF-8, UTF-16 or other encodings are not supported. Any use of a non-supported encoding can produce errors or unexpected behaviors.

toInt()

Returns an integer representation of this string object. If this string does not represent an integer or if the conversion is not possible (out of range), an exception is thrown.

toDouble()

Returns a float representation of this string object. If this string does not represent a float or if the conversion is not possible (out of range), an exception is thrown.

split()
split(delimiter)

Returns a map that contains the substrings of this string object that are delimited by the given delimiter. For example "a::b::::c".split("::") returns {"a", "b", "", "c"}.

If no delimiter is provided, whitespaces are used as delimiter. In that case consecutive whitespaces are considered as a single separator. Thus a string composed of whitespaces only, always returns an empty map {}.

Splitting an empty string with or without a delimiter always returns an empty map {}.

Parameters:delimiter (string) – Delimiter used to split the string. This parameter is optionnal. If no delimiter is provided, whitespaces are used by default.
Returns:A map containing the splitted substrings
Return type:map
trim()

Returns a copy of the string with leading and trailing whitespaces removed. The list of whitespaces is the same as the list used for the function isSpace().

length()

Returns the length of the string as integer.

startsWith(prefix)

Returns true if the string starts with the given prefix. If the prefix is an empty string, returns true.

Parameters:prefix (string) – The prefix.
endsWith(suffix)

Returns true if the string starts with the given suffix. If the suffix is an empty string, returns true.

Parameters:prefix (string) – The suffix.
toLowerCase()

Returns a new string with all the characters converted to lower case.

toUpperCase()

Returns a new string with all the characters converted to upper case.

replace(search, replace)

Return a copy of the string with all occurrences of substring search replaced by replace.

Parameters:
  • search (string) – Search string. Throws an exception if this argument is empty.
  • replace (string) – Replace string.
isLower()

Returns true if the string contains only characters that are lowercase and there is at least one character, false otherwise.

isUpper()

Returns true if the string contains only characters that are uppercase and there is at least one character, false otherwise.

isLetter()

Returns true if the string contains only letters and there is at least one character, false otherwise.

isDigit()

Returns true if the string contains only digits and there is at least one character, false otherwise. The complete list of digits is “0123456789”.

isSpace()

Returns true if the string contains only whitespace characters and there is at least one character, false otherwise. White-spaces characters are:

  • ” ” (0x20) space
  • “\t” (0x09) horizontal tab
  • “\n” (0x0a) newline
  • “\v” (0x0b) vertical tab
  • “\f” (0x0c) feed
  • “\r” (0x0d) carriage return
indexOf(search)
indexOf(search, start)

Returns the first position of the substring search in the string. If no start position is given, the search starts at the beginning of the string. Returns -1 if the substring is not found.

Parameters:
  • search (string) – Substring to search
  • start (int) – The position to start the search from. If the start position is negative, an exception is thrown.
substring(start)
substring(start, length)

Returns a new string that is a substring of this string. There are two versions of this function:

  • In the first version, the function takes one argument. In that case, the returned substring starts at the given position and goes to the end of the string.
  • In the second version, the returned substring starts at the given position and goes to the character at position start + length - 1.
Parameters:
  • start (int) – Start position. If the start position is negative or greater than the length of the string, an exception is thrown.
  • length (int) – Length of the substring (optionnal). If the given length is negative, an exception is thrown.