How to use variables in the Substring function?

I used the Substring function to extract a part of the string.
But “Start character position” and “End character position” cannot use variables, only can use static value.
Is there any way to solve this problem?
Thank you.

1 Like

Hi @ShawnLi you cannot use variables in the Substring action. You can use this custom action as a workaround:

input = ['str_original','start','end'],
output = 'str_result'
def customScript() {
str_result = str_original[start..end]

where start and end are recorder variables of type Number.


Hi @ashapkina, thank you for your prompt reply. The script works perfectly!
Screen captures for reference.

Execution result:

1 Like

Great :smiley: Glad it helps!