How to substract a string

how to substract the following string

13XX20-1 using assign activity

Output should be 13XX19

Consider following things about the pattern of the string on the left, i.e. 13XX20.
Does it always start with 13XX?
Is the number on the right always 2 digit? Could it be 3 digit, such as 13XX120?

In any case, depending on the pattern, you will need to reliably isolate the number at the end of the string, just before the subtraction sign. Parse it to an Integer using CType(variable, Integer) and then do the subtraction.

1 Like

Variable1=“13XX20-1”
If Variable1.Contains(“-”)
Then
NewVar=SPLIT(variable1,“XX”)(0)+“XX”+(Cint(variable1.Split({“XX”},StringSplitOptions.None)(1).Trim.Split({“-”},StringSplitOptions.None)(0))-CInt(split(variable1,“-”)(1))).tostring

Else If Variable1.Contains(“+”)
NewVar=SPLIT(variable1,“XX”)(0)+“XX”+(Cint(variable1.Split({“XX”},StringSplitOptions.None)(1).Trim.Split({“+”},StringSplitOptions.None)(0))+CInt(split(variable1,“+”)(1))).tostring

1 Like

Hi value is 13XX20 and i have to subtract 1 from the value.

yes it is always 2 digit.

Use above code then part only the. Dont use condition

1 Like

NewVar=SPLIT(variable1,“XX”)(0)+“XX”+(Cint(variable1.Split({“XX”},StringSplitOptions.None)(1).Trim.Split({“-”},StringSplitOptions.None)(0))-CInt(split(variable1,“-”)(1))).tostring

1 Like