Hi,
I have the following problem:
I have old word documents, containing mergefields and If’s.
For instance:
MERGEFIELD M_1
MERGEFIELD 2
{ IF { MERGEFIELD M_3 } = “This is Three” “{MERGEFIELD “M_4”}” “” }
Some of the mergefields are named M_, others are just .
What I want is to change the MERGEFIELD 2 to MERGEFIELD M_2. This is no problem using a variant of following code.
Variant :
Integer getal = null;
try{getal = Integer.parseInt(mergeField.getName());}catch(NumberFormatException ex){}
if(getal != null)
mergeField.setName(“M_” + getal.toString());
I expected this to only find the MERGEFIELD 2… it however finds the MERGEFIELD M_3 and MERGEFIELD M_4 as well. Because they are inside the IF, the mergeField.getName() returns 3 and 4, instead of M_3 and M_4. Does anyone have any suggestions on how to overcome this problem?
Thanks!
Kind Regards
Matthias