I have a string variable which contains only one letter like "D" or "A" etc.
I want to replace this letter by an explicit text but when I do (in this case "$F{Action}" contain "D"):
$F{Action}.replace('D','Apple').replace('A','text')
my result is "textpple" Because Apple beginning with an "A" and my second replace is on the letter "A"
How can I do to only replace the letter by the first replace statement and not do the others replace statement?
There is no need of scriptlet for this small work. You can try using the below expression
$F{Action}.contains( "D" ) ? "Apple" : $F{Action}.contains( "A" ) ? "text" : ""
Hope this is your requirement.