Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Pull text from parenthesis Post Reply Post New Topic
Author Message
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Topic: Pull text from parenthesis
     Posted: 15 Aug 2012 at 2:07am
I have the following text in a field
Let's call it Name_Field

this is what the data looks like in the name field.

FirstName LastName (FLastname)
or it would look like this
John Doe (JDoe)

I either need to grab the first and last name out - or just grab the text between the parenthesis.

I am not sure how to use the InStr to do this.
IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 15 Aug 2012 at 2:38am
stringvar str1 := Name_Field                  //'John Doe (JDoe)';
stringvar str2;
numbervar br;
br := instr(str1,'(');
str2 := mid(str1,br+1);
br := instr(str2,')');
str2 := left(str2,br-1);
str2
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 15 Aug 2012 at 4:18am
Or, if ')' is always the last character in the field, you could tweak yggdrasil's formula to do something like this:
 
stringvar str2;
numbervar br := instr({MyTable.MyField}, '(');
numbervar len := length({MyTable.MyField}) - br - 1;
str2 := mid({myTable.MyField}, br + 1, len);
str2
 
-Dell
IP IP Logged
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Posted: 15 Aug 2012 at 4:29am
Why can't I get the formula to work?  It comes back...."The remaining text does not appear to be part of the formula.

This happens of the stringvar str2;   line
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 15 Aug 2012 at 4:43am
Please copy and paste your entire formula into a post here so that we can see it.  Also, where are you creating this?  Are you creating a Formula or a SQL Expressing?  You need to be creating a Formula.
 
-Dell
IP IP Logged
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Posted: 15 Aug 2012 at 4:59am
stringvar str1 := {store_audit.submitted_by}                 //'John Doe (JDoe)';
stringvar str2;
numbervar br := instr({store_audit.submitted_by} , '(');
numbervar len := length({store_audit.submitted_by} ) - br - 1;
str2 := mid({store_audit.submitted_by} , br + 1, len);
str2
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 15 Aug 2012 at 6:01am
You need to move the semi-colon on the first line so that it looks like this:
 
stringvar str1 := {store_audit.submitted_by};
 
-Dell


Edited by hilfy - 15 Aug 2012 at 6:01am
IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 21 Aug 2012 at 3:24am
That was my fault in the first post Embarrassed
The ; got left after the comment inadvertently
Sorry.
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