Skip to main content

String

A string is an immutable sequence of characters. See Strings for an overview of strings.

The following operations are supported for strings:

+ : (String, String) -> String

Concatenates two strings.

* : (String, Integer) -> String

Given a string and an integer n, repeats the string n times.

[] : (String, Integer) -> char

Given a string and an index, returns the character at the given index in the string.

~ : (String) -> Pattern

Creates a regular expression from a string. See Pattern in the Java standard library for more information.

=~ : (String, String) -> Matcher

Given a string and a pattern, creates a matcher that is truthy if the pattern occurs anywhere in the string. See Matcher in the Java standard library for more information.

==~ : (String, String) -> Boolean

Given a string and a pattern, returns true if the string matches the pattern exactly.

The following methods are available for a string:

contains( str: String ) -> Boolean

Returns true if the given substring occurs anywhere in the string.

endsWith( suffix: String ) -> Boolean

Returns true if the string ends with the given suffix.

execute() -> Process

Execute the string as a command. Returns a Process which provides the exit status and standard input/output/error of the executed command.

indexOf( str: String ) -> Integer

Returns the index within the string of the first occurrence of the given substring. Returns -1 if the string does not contain the substring.

indexOf( str: String, fromIndex: Integer ) -> Integer

Returns the index within the string of the first occurrence of the given substring, starting the search at the given index. Returns -1 if the string does not contain the substring.

isBlank() -> Boolean

Returns true if the string is empty or contains only whitespace characters.

isEmpty() -> Boolean

Returns true if the string is empty (i.e. length() is 0).

isDouble() -> Boolean

Returns true if the string can be parsed as a 64-bit (double precision) floating-point number.

isFloat() -> Boolean

Returns true if the string can be parsed as a 32-bit floating-point number.

isInteger() -> Boolean

Returns true if the string can be parsed as a 32-bit integer.

isLong() -> Boolean

Returns true if the string can be parsed as a 64-bit (long) integer.

lastIndexOf( str: String ) -> Integer

Returns the index within the string of the last occurrence of the given substring. Returns -1 if the string does not contain the substring.

lastIndexOf( str: String, fromIndex: Integer ) -> Integer

Returns the index within the string of the last occurrence of the given substring, searching backwards starting at the given index. Returns -1 if the string does not contain the substring.

length() -> Integer

Returns the length of the string.

md5() -> String

Returns the MD5 checksum of the string.

replace( target: String, replacement: String ) -> String

Returns a new string in which each occurrence of the target string is replaced with the given replacement string.

replaceAll( regex: String, replacement: String ) -> String

Returns a new string in which each occurrence of the given regular expression is replaced with the given replacement string.

replaceFirst( regex: String, replacement: String ) -> String

Returns a new string in which the first occurrence of the given regular expression is replaced with the given replacement string.

sha256() -> String

Returns the SHA-256 checksum of the string.

startsWith( prefix: String ) -> Boolean

Returns true if the string ends with the given prefix.

strip() -> String

Returns a copy of the string with all leading and trailing whitespace removed.

stripIndent() -> String

Returns a copy of the string with leading spaces on each line removed. The number of spaces to remove is determined by the line with the least number of leading spaces, excluding lines with only whitespace.

stripLeading() -> String

Returns a copy of the string with all leading whitespace removed.

stripTrailing() -> String

Returns a copy of the string with all trailing whitespace removed.

substring( beginIndex: Integer ) -> String

Returns a substring of this string.

substring( beginIndex: Integer, endIndex: Integer ) -> String

Returns a substring of this string.

toBoolean() -> Boolean

Returns true if the trimmed string is "true", "y", or "1" (ignoring case).

toDouble() -> Float

Parses the string into a 64-bit (double precision) floating-point number.

toFloat() -> Float

Parses the string into a 32-bit floating-point number.

toInteger() -> Integer

Parses the string into a 32-bit integer.

toLong() -> Integer

Parses the string into a 64-bit (long) integer.

toLowerCase() -> String

Returns a copy of this string with all characters converted to lower case.

toUpperCase() -> String

Returns a copy of this string with all characters converted to upper case.

tokenize( delimiters: String ) -> List<String>

Splits the string into a list of substrings using the given delimiters. Each character in the delimiter string is treated as a separate delimiter.

note

Strings in Nextflow are backed by the Java and Groovy standard libraries, which may expose additional methods. Only methods which are recommended for use in Nextflow are documented here.

On this Page