4

How can I use String and Integer variables it together in "Velocity"?

#set ($var1 = "exp"+1)

I tried a few times but I could not.

Any help will be highly appreciated.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
ahta14
  • 115
  • 3
  • 9

1 Answers1

7

If you were trying to do concatenation, it's not supported by Velocity, not even for 2 Strings. Instead, you should use string interpolation. Example:

#set ($string = "exp")
#set ($number = 1)
#set ($interpolatedExample1 = "$string$number")
#set ($interpolatedExample2 = "${string}someStringLiteral$number")

Read more details and examples in the documentation.

Eduard Moraru
  • 770
  • 4
  • 9