Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Need Help, Formula to Extract Email address Post Reply Post New Topic
Author Message
dajon
Newbie
Newbie


Joined: 15 Oct 2009
Online Status: Offline
Posts: 3
Quote dajon Replybullet Topic: Need Help, Formula to Extract Email address
     Posted: 15 Oct 2009 at 8:19am
I have a string value that contains a name and an email address. I do not have control over how this is stored in the database, but I need a way to extract the name and email address. Here is an example of text in the string.
 

proof date 10/13

PDF to Joe Blow  email@emailaddress.com

 
What would be the best way to get these values out of this string?
 
Thanks,
 
Jon
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 15 Oct 2009 at 10:13am
I can get you the email, but we may need an expert in here to get the rest.
 
I practiced with the field {table.emailfield} that had the data:
 
     Tom Jones lestat_66683@yahoo.com
 
I made one formula called {@Reverse} that is:
 
     strreverse({table.emailfield})
 
Then made a formula called {@email} that is:
 
     strreverse(split({@Reverse}, ' ') [1])
 
{@email} may also be:
 
     strreverse(left({@email}, instr({@email}, ' ')-1))
 
These, however,will only give you the email correctly if the name is separated from the email by one space and if the email address is the last item in the string.
 
Maybe this will help to spark something and you can take it from there.
 
Any experts want to get in on this?
 
 
 
For the name:
 
if all you have in the field is the Name and email, then do what is above, then make another field {@name} that is:
 
     if {@email} in {table.emailfield}
         then replace({table.emailfield},
{@email}, '')
 
This returned to me Tom Jones.


Edited by FrnhtGLI - 15 Oct 2009 at 10:27am
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 15 Oct 2009 at 10:37am
Okay, another, easier way to get the email is one field {@email} that is:
 
     global stringvar nReverse:= strreverse({table.emailfield});
 
     nReverse:= strreverse (left(nReverse, instr (nReverse, ' ')-1));
 
     nReverse;
 
Then to get the name, {@name}:
 
     if {@email} in {table.emailfield}
          then replace({table.emailfield}, {@email}, ' ')


Edited by FrnhtGLI - 15 Oct 2009 at 10:38am
IP IP Logged
dajon
Newbie
Newbie


Joined: 15 Oct 2009
Online Status: Offline
Posts: 3
Quote dajon Replybullet Posted: 15 Oct 2009 at 11:23am
This could work, however they do not only type the name and email address. They type additional notes as well. I am trying to convince them that storing all this data in one big field is not good planning and they should have separate fields for name, email, and notes.
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 15 Oct 2009 at 11:33am
The next best thing would then be to have the field delimited with a semicolon or colon, so then it would be:
 
PDF to ; Joe Blow ; email@emailaddress.com ;
 
Then you could just use the split function to get the pieces you need. For this to work properly, though, the Notes, Name and Email would need to be in the same section every time. For example, have notes be first, then name, then email. Then for each section you could just do:
 
     split({table.emailfield}, ';')[1]//notes
     split({table.emailfield}, ';')[2]//name
     split({table.emailfield}, ';')[3]//email
 
You could still keep all the information in one field and just make a small change that will have an enormous impact on the report design.


Edited by FrnhtGLI - 15 Oct 2009 at 11:38am
IP IP Logged
dajon
Newbie
Newbie


Joined: 15 Oct 2009
Online Status: Offline
Posts: 3
Quote dajon Replybullet Posted: 15 Oct 2009 at 1:43pm
The problem is that the users would have to remember to put the semicolons, or commas, or whatever other delimiter. One big problem I am having is that users are very inconsistent when it comes to data entry. I will run this by them as it seems like the simplest way to accomplish the goal.

Thanks,
 
Jon
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 16 Oct 2009 at 5:41am
I understand. I have the same problems with some of my reports.
 
I guess that I was assuming that it was three separate fields from the database being combined into one field for the report. I didn't realize it was all just one field.
 
Well, I'd be interrested in finding out what your solution is when you come to it.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum