I'm trying to get the last element of an array in a velocity template dropped before joining it together into a string and showing the result in the "className": key below:
#set($elem = '"System.NotImplementedException: Test Exception')
#set($trace = $elem.replace('"',""))
#set($tracearray = $trace.split("\."))
#set($arraysize = $tracearray.size())
#set($lastelem = $tracearray.size() - 1)
{
"className":$tracearray.remove($lastelem).toString(),
"method":"$tracearray[$lastelem]"
}#if($foreach.hasNext),#end
#end
]
I've tried several different ways to get the array to drop the element and join it together into a string but haven't had any luck so far.
From the above example I'm looking for the following output to be achieved.
{
"className":"System",
"method":"NotImplementedException: Test Exception"
}
The $elem
variable will be holding strings of various lengths and with a different number of .
's in them to split on so the lengths of the arrays will vary.