Replacing last 2 letters of name using velocity script
Hi Champions,
I want to write a script to replace last two letters of the first name, I have 5 conditions to solve here.
- If name has ending -as, then salutation ends – ai. Example: Rokas – Rokai, Mindaugas – Mindaugai
- if ending -is, then salutation ends -i. Example: Rytis – Ryti, Kęstutis – Kęstuti
- if ending -ys, salutation -y. Example: Balys – Baly, Kazys – Kazy
- If ending -us, salutation ends -au. Example: Paulius – Pauliau, Baltrus – Baltrau
- If ending -ė, salutation ends -e. Example: Auksė – Aukse, Kamilė – Kamile
I am trying to decode it step by step and written below script to solve condition 1 (Replace as with ai)
#set( $Name = ${lead.FirstName} )
#set( $FormatName = $Name.trim().replaceAll("(.*)as", "ai") )
${FormatName}
The above script is replacing whole word instead of just "as", any help here is much appreciated.
