Avatar of Mark Wilson
Mark Wilson
 asked on


I am using Crystal Reports XI R2

I have a field with the following sort of data in it.

Wills for John Smith
Will for John Bloggs
LPA for Esther & John Smith

I am looking to extract the names from the field only

At the moment I am doing

if field startswith 'Will for' then replace(field,'Will for ','') else
if field startswith 'Wills for' then replace(field,'Wills for ','') else etc

Is there an easier or more succinct way of doing this
Crystal Reports

Avatar of undefined
Last Comment
Mark Wilson

8/22/2022 - Mon

if you are looking anywhere in the string fro a name you could use instr(uppercase({field}),"WILL" )

it will return a value greater than 0 showing the starting point of the test string WILL.  This will allow you to look anywhere in the string, not just the beginning.

I forgot to mention,  there is a variant of the replace string that allows you to control starting position

you could also create a list in an array  with various names and do a loop to search and replace without having to execute  additional if statements
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Mike McCracken

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mark Wilson


Local StringVar strNewList;

strNewList := Replace({YourField},'Will for',"");
strNewList := Replace(strNewList ,'Wills for',"");
strNewList := Replace(strNewList ,'LPA for',"");

strNewList  := Trim(strNewList);

Thats exactly what I am looking for thanks
Mark Wilson

I've requested that this question be closed as follows:

Accepted answer: 0 points for halifaxman's comment http:/Q_27250663.html#36356171

for the following reason:

Thanks for your help
Mark Wilson


I have picked the myself as the solution which is incorrect. Can you cancel this so I can pick the right one

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.