Jump to content
We've recently updated our Privacy Statement, available here ×

find and replace character from right


zaila_1

Recommended Posts

Hi, 
I have string with commas.  I want to replace last comma with ' and ' 

eg: sunday, monday, tuesday   ->  sunday, monday and tuesday
      apple, banana, strawberry, lemon  ->    apple, banana, strawberry and lemon

 

thank you

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 8.0.1.final using JasperReports Library version 6.11.0  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="demo20220303" pageWidth="612" pageHeight="792" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6a28a568-5cd4-4fc1-9e28-015213d63b58">
    <parameter name="Input String" class="java.lang.String">
        <defaultValueExpression><![CDATA["apple, banana, strawberry, lemon"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <title>
        <band height="79" splitType="Stretch">
            <textField>
                <reportElement mode="Opaque" x="0" y="0" width="570" height="30" backcolor="#FFFF00" uuid="e4fc6e91-9a90-4b32-98e2-7355e3b81afe"/>
                <textFieldExpression><![CDATA["INPUT STRING: "+$P{Input String}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="1" y="40" width="570" height="30" backcolor="#33FF00" uuid="323b73b5-269c-42ad-a1ad-a6689316fc8c"/>
                <textFieldExpression><![CDATA["Modified String: "+$P{Input String}.replaceFirst(",([^,]+)$", " and$1")]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

 

screenshot_2011.thumb.png.de5334a917e668e2cc90335e1e2dbe18.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...