Extracting Characters from Harness Variable Expressions
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.buildNo}
, ${artifact.revision}
, or Service and Workflow variables you have created that contain version numbers or other important strings.
To return characters, you can use the charAt()
method with your variable expression.
Step 1: Use the charAt() Method
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.