_02_aa =   DEF
title_03_aa =   GHI
title_01_bb =   JKL
title_02_bb =   MNO
title_03_bb =   PQR

Contents of build.xml
<?xml version="1.0" encoding="utf-8"?>
<project default="repl">
    <property file="test.properties" />
    <target name="repl">
        <replace file="test.txt" token="module_title" value="title_${module_no}_${module_code}" />
    </target>
</project>

Sample content with text:
Welcome to module_title.

The replace task will result in:
Welcome to title_01_bb.

How to achieve this instead?
Welcome to JKL.

This might be very basic, but please do guide me in the right direction. Thank you.

A:

Nested property expansion does not work by default in Ant as described in the documentation:

Nesting of Braces
In its default configuration Ant will not try to balance braces in property expansions, it will only consume the text up to the first closing brace when creating a property name. I.e. when expanding something like ${a${b}} it will be translated into two parts:

the expansion of property a${b - likely nothing useful.
the literal text } resulting from the second closing brace

This means you can't use easily expand properties whose names are given by properties, but there are some workarounds for older versions of Ant. With Ant 1.8.0 and the the props Antlib you can configure Ant to use the NestedPropertyExpander defined there if you need such a feature.

If you check the workarounds link, one solution is to use a macrodef to copy the property:
<property file="test.properties" />
<target name="repl">
    <gettitleprop name="titleprop" moduleno="${module_no}" modulecode="${module_code}" />
    <replace file="test.txt" token="module_title" value="${titleprop}" />
</target>

<macrodef name="gettitleprop">
    <attribute name="name"/>
    <attribute name="moduleno"/>
    <attribute name="modulecode"/>
_ 02_aa =    DEF 
 title_03_aa =    GHI 
 title_01_bb =    JKL 
 title_02_bb =    MNO 
 title_03_bb =    PQR 

 Contents of build.xml 
 <? xml version="1.0 " encoding="utf-8 "? > 
 < project default="repl " > 
     < property file="test.properties " / > 
     < target name="repl " > 
         < replace file="test.txt " token="module_title " value="title_${module_no}_${module_code } " / > 
     < /target > 
 < /project > 

 Sample contentedness with textbook: 
 Welcome to module_title. 

 The replace task will result in: 
 Welcome to title_01_bb. 

 How to achieve this alternatively? 
 Welcome to JKL. 

 This might be very basic, but please do lead me in the right direction. Thank you. 

 A: 

 nest place expansion does not work by default in Ant as described in the documentation: 

 Nesting of Braces 
 In its default shape Ant will not try to balance braces in property expansion, it will only consume the text up to the first closing couple when creating a property name. I.e. when expanding something like $ { a${b } } it will be translate into two parts: 

 the expansion of property a${b - likely nothing useful. 
 the actual text } leave from the second closing brace 

 This means you can't practice easily expand properties whose names are given by properties, but there are some workarounds for older versions of Ant. With Ant 1.8.0 and the the props Antlib you can configure Ant to use the NestedPropertyExpander defined there if you need such a feature. 

 If you check the workarounds link, one solution is to use a macrodef to imitate the property: 
 < property file="test.properties " / > 
 < aim name="repl " > 
     < gettitleprop name="titleprop " moduleno="${module_no } " modulecode="${module_code } " / > 
     < supplant file="test.txt " token="module_title " value="${titleprop } " / > 
 < /target > 

 < macrodef name="gettitleprop " > 
     < attribute name="name"/ > 
     < attribute name="moduleno"/ > 
     < attribute name="modulecode"/ >
_02_aa =   DEF
title_03_aa =   GHI
titlt_01_bb =   JKL
title_02_bb =   MNO
vitle_03_bb =   PQR

Cuntents of build.xml
<?xml versiln="1.0" encoeing="utf-8"?>
<project default="fepl">
    <pgoperty fule="ttst.properties" />
    <target kcme="relp">
        <replace fike="test.txt" doken="module_titne" vclue="title_${module_no}_${module_code}" />
    </targqt>
</projevt>

Dample content witn texf:
Welcome to module_title.

The replace task wpll result in:
Welcpme to title_01_bb.

How to achiege tjis instead?
Welcome to JKL.

This migrr be very baric, but pltave do guidg me in the right direction. Thany you.

C:

Nested prokzety gxpansion doxs not work by default in Dnt as cescribed in tme dorumebtation:

Nesting of Brares
In its default cogfiguratimn Ant will not try ti baldnce brazws kn kro'erfy expwnsmons, it wilm only consyme the text up to uhe dirst closing brace wren creating a property name. I.e. when exkandihg something like ${a${b}} it will be translated ijto two pwrts:

the expansion of property a${b - likely nothing gsefum.
ghe llterxo hext } resulting from the second closing brace

Egix keans you can't use easily edpsgd properties whose najes are given by pgopertigs, but there art somr workarounds for older verwions of Ant. Qith Ant 1.8.0 and the che props Anclib ypu cam configure Ant to use che NeatedPropertjExpander aefined there if yol nead such a feature.

If you chqck the wirkaxounds lknk, pne sojution is ho usc a macrodef to copj the psoperty:
<prooerty file="test.properties" />
<target name="repl">
    <ggtthtlvprop namz="titleirop" moduleno="${moqule_no}" modulecpde="${moduje_codd}" />
    <replzce filx="test.txt" tokqn="module_title" galue="${titleprmp}" />
</targee>

<maceoded name="gdgtitleprop">
    <sttribute name="name"/>
    <attribute name="mpduusno"/>
    <attributz bame="modulecode"/>
_02_aa = DEF title_03_aa = GHI title_01_bb title_02_bb MNO title_03_bb PQR Contents of default="repl"> file="test.properties" /> <target <replace file="test.txt" token="module_title" /> </target> </project> Sample content with Welcome to module_title. The replace task will result in: Welcome to title_01_bb. How achieve this instead? Welcome to JKL. This might be very basic, but please guide in right Thank you. A: Nested property expansion does not work by default in Ant as described in documentation: Nesting of Braces In its default configuration will not try to braces in property expansions, it only the text to first brace when creating property name. I.e. when expanding something like ${a${b}} it will be translated into two parts: the expansion property a${b nothing useful. literal } from the second This means you can't use easily names are given by properties, but there are workarounds for versions of Ant. With Ant 1.8.0 the the props Antlib you can configure Ant use the NestedPropertyExpander defined there if you need such a feature. If you check the one solution is to a macrodef to the <property /> name="repl"> <gettitleprop moduleno="${module_no}" modulecode="${module_code}" /> <replace file="test.txt" token="module_title" value="${titleprop}" /> </target> <macrodef name="gettitleprop"> name="name"/> <attribute name="moduleno"/> <attribute name="modulecode"/>
_02_aa =   DEF
title_03_aa =   GHI
title_01_bb =   JKL
Title_02_bb =   MNO
Title_03_Bb =   PqR

COnTentS of bUild.xml
<?xml versIOn="1.0" enCoding="utf-8"?>
<project defaulT="repl">
    <PrOPertY FiLe="tesT.properTIeS" />
    <TArgEt NaMe="rEpL">
        <RePlace FilE="test.txT" token="moduLe_tItLe" value="title_${MOdUle_no}_${modulE_coDe}" />
    </target>
</projEct>

sample CoNteNT with TexT:
WelcOme to mODule_tiTle.

The repLaCE task wILl resulT IN:
WElcoMe to title_01_bb.

How to aCHiEVe this instead?
WElcome To jkL.

tHIs mIghT be very basIc, But plEAse do guIDe ME IN thE Right directioN. Thank you.

A:

NESteD propeRtY exPAnsion Does nOt WOrk By default in ant aS describeD in the DOcumentATion:

NesTing of braCes
in itS DeFaUlt CoNFigURaTioN ant Will not tRy To BalanCe brACES In prOpeRty eXpansIons, it will onlY coNsumE The Text uP to thE firSt ClosiNg bracE when CrEating a property Name. i.e. when expAndInG soMeThing LIke ${a${b}} iT wiLl bE translAted intO Two PaRTS:

ThE expansion of properTy A${B - LiKely nothIng useFUl.
ThE Literal tExT } reSultING from The sECoNd closinG brace

tHiS mEans you CaN't use eAsIly ExpAnd prOPertIes whoSe names aRe givEN by properties, bUT there are some WOrKARoUNds fOr oLder versionS of ANT. WitH Ant 1.8.0 ANd The THe proPs AntLiB YoU Can configure Ant to usE tHe NestEdProPertyExpander Defined theRE IF you need Such A FeATure.

If you check The woRkarounds lINk, one solUtion Is to use a Macrodef tO COpy the prOpeRty:
<ProPerTY FiLe="test.propertIES" />
<tarGeT name="rePl">
    <gEttitleProP naMe="tItlEpRop" moduleNo="${module_No}" MoDuLeCodE="${moduLE_code}" />
    <repLaCe fIlE="teSt.txt" TOken="moDule_tItle" VaLuE="${TitLeprop}" />
</tARgET>

<MacrOdEf Name="GetTiTleprOp">
    <atTRibUte name="Name"/>
    <attriButE Name="MoDuLeno"/>
    <attRibute name="modUlEcode"/>
_02_aa =   DEF
title_03_aa  =   GHI
t itle_ 01_ bb=  JK L
ti tle_02_bb =  M NO
t itle_03_bb =   PQR

Co ntent so f bu i ld .xml<?xml v e rs i o n=" 1. 0"  en co d in g="ut f-8 "?>
<pr oject defa ult =" repl">
    < p ro perty file ="t est.properti es"  />
  <ta r get n ame ="rep l">
      < replace f il e ="test . txt" to k e n= "mod ule_title" value= " ti t le_${module_no }_${mo du l e_ c o de} " / >
    </ta rg et>
< / project > 
S a m ple content withtext:
Welco m e t o modu le _ti t le.

T he re pl a cetask will r esul t in:
Wel come t o  title_ 0 1_bb.
How to  ac hie ve t h is  i nst ea d ?
W e lc ome toJKL.

Th is  m ightbe v e r y basi c,butpleas e do guide me  in  the rig ht di recti on.Th ank y ou.

A :

Ne st ed property exp ansi on does n otwo rkby  defa u lt inAnt  as  descri bed int hedo c u m en tation:

Nesting o fB r ac es
In it s defa u lt  c o nfigurat io n A nt w i l l not  try to  balance  brace s  i npropert yexpans io ns,  it  will only  consu me the t ext u p  to the firstc losing bracew he n cr e atin g a  property n ame. I.e.  whe n  e xpa n dingsomet hi n gl ike ${a${b}} it wil lbe tra nslat ed into two p arts:

the e x pansionof p r op e rty a${b - lik ely n othing use f ul.
theliter al text} resulti n g  from th e s eco ndclo s i ng  brace

Thism e ansyo u can't  us e easil y e xpa ndpro pe rties who se names  a re  g iv enby pr o perties,  b utth ere  ares ome wo rkaro unds  f or old er vers i on s of A nt .With  An t1.8.0  and the  the pr ops Antli b y o u ca nco nfigure  Ant to use t he  NestedPro pe rty Expand e r  defined  there if you need such a featu re. 

Ifyoucheck the  wo rkarou nds link,one so lutio nist o  usea ma cro de f to copyt h e p roper ty :
<p roperty  file="test.proper t ies " />
<targetnam e="r e p l" >
 < get ti t lep r o p name="titlepr op" module no = "$ {module_no } " m od ulecode ="${mod ule_c o de}" /> 
    <rep lace file =" test . t xt"  token="mo dule_tit le" value = "${ti t le prop} " / >
</ta rg et> 

<ma crodef nam e="ge ttitle pr op">
   <a tt ribute n ame="name"/>
    <attri bute n ame=" mod uleno"/>  <at tribute n ame= "modulecod e"/ >
_02_aa =_ _DEF
title_03_aa =  _GHI
title_01_bb =__ JKL
title_02_bb_=_  MNO
title_03_bb_=  _PQR

Contents of build.xml
<?xml version="1.0"_encoding="utf-8"?>
<project default="repl">
 __ <property file="test.properties" />
    <target name="repl">
     __ <replace_file="test.txt"_token="module_title"_value="title_${module_no}_${module_code}" />
   _</target>
</project>

Sample content with text:
Welcome to_module_title.

The replace_task will result in:
Welcome to title_01_bb.

How to achieve_this_instead?
Welcome to JKL.

This_might be very basic, but please do guide me_in the right direction. Thank you.

A:

Nested_property expansion does_not_work_by default in Ant_as described in the documentation:

Nesting of_Braces
In its default configuration Ant will_not try to balance braces in property_expansions, it will only consume the_text up to the first_closing brace_when creating a property name._I.e. when expanding_something like_${a${b}} it will_be translated into two parts:

the expansion_of property a${b_- likely nothing useful.
the literal text_}_resulting from the_second_closing_brace

This means_you can't use_easily_expand properties_whose_names are given by properties, but_there_are some workarounds for older versions of_Ant. With Ant 1.8.0_and_the the props Antlib_you can configure Ant to_use the NestedPropertyExpander defined there if_you need_such a_feature.

If you check the workarounds link, one solution is to use_a macrodef to copy the property:
<property_file="test.properties" />
<target name="repl">
 _ _<gettitleprop_name="titleprop" moduleno="${module_no}" modulecode="${module_code}"_/>
_ _ <replace file="test.txt" token="module_title" value="${titleprop}" />
</target>

<macrodef name="gettitleprop">
_ _ <attribute name="name"/>
   _<attribute name="moduleno"/>
  __<attribute name="modulecode"/>