Skip to main content

Extracting characters from Harness variable expressions

You can use any Java String method to extract characters or manipulate strings with expressions.

Example: Use the charAt() method

For example, you can return the character at a specified index in a Harness variable expression string.

This can be helpful with built-in variable expressions such as <+artifact.tag>, <+artifact.image>, or variables that contain version numbers or other important strings.

To return characters, you can use the charAt() method with your variable expression.

Let's look at an example where you have a variable named <+version>. that evaluates to 1234.

To get the first character of the string, you would use <+<+version>.charAt(0)>. This would return 1.

The <+version> references the variable, and the rest of the expression evaluates the string using the charAt() method.

See also