Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mergefield help

Status
Not open for further replies.

weeze2

Technical User
Jun 18, 2002
129
DK
Hi

Is there some way to test part of a string in an "IF THEN ELSE" mergefield? - Sort of like a Left() or substring function but for mergefields.

{ IF { MERGEFIELD fieldname } = "qwerty" "y" "z" }

For example if fieldnames length is unknown, can one test for "qwe" to give y and "qwerty" or "qwertyuiop" and everything else to give z?

Thank you :)
 
I solved it with the COMPARE keyword.

COMPARE expression1 operator expression2

 
Hi weeze2,

To test whether the string begins with 'qwerty', you could use:
{IF{MERGEFIELD fieldname}= "qwerty*" "y" "z"}
Conversely, to test whether the string ends with 'qwerty', you could use:
{IF{MERGEFIELD fieldname}= "*qwerty" "y" "z"}

Cheers

[MS MVP - Word]
 
I did not know one could use * in the IF expessions.

Thanks!
 
Hi weeze2,
I did not know one could use * in the IF expessions.
You can also use '?'. You'd use this if you know exactly how many characters from the start or end of the field your test string is.

To test whether the string has three unspecified characters at the start followed by 'rty', you could use:
{IF{MERGEFIELD fieldname}= "???rty*" "y" "z"}
Conversely, to test whether the string ends with 'rty' followed by three unspecified characters, you could use:
{IF{MERGEFIELD fieldname}= "*rty???" "y" "z"}

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top