groovy split string

Groovy: Splitting a String

To split a string in Groovy, you can use the split() method. This method splits a string into an array of substrings based on a specified delimiter. Here's the syntax:

String[] splitString = yourString.split(delimiter)
  • yourString is the string you want to split.
  • delimiter is the character or regular expression pattern that specifies where to split the string.

The split() method returns an array of substrings.

For example, let's say you have the following string:

String myString = "Hello,World,How,Are,You"

If you want to split the string at each comma (,), you can use the following code:

String[] splitString = myString.split(",")

After executing this code, the splitString array will contain the following elements:

["Hello", "World", "How", "Are", "You"]

That's how you can split a string in Groovy using the split() method.