Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Extract text from memo field Post Reply Post New Topic
Author Message
msnoshoes
Newbie
Newbie


Joined: 10 Sep 2009
Location: United States
Online Status: Offline
Posts: 9
Quote msnoshoes Replybullet Topic: Extract text from memo field
     Posted: 03 Feb 2012 at 7:42am
I have a a memo field that looks like this that may or may not contain the following phrase:
 
Agency>                <Company
 
If it does, I want to show only the text between Agency> and <Company
 
I have no clue how to do this.
Any help would be greatly appreciated.
Thanks!
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 03 Feb 2012 at 9:00am
numbervar endposition:= instr(mid({table.field}, instr({table.field}, '>') +1), '<')-1;

mid({table.field}, instr({table.field}, '>') +1, endposition);


Let me know if that gets you what you are looking for.
|< /\ '][' ( )
IP IP Logged
msnoshoes
Newbie
Newbie


Joined: 10 Sep 2009
Location: United States
Online Status: Offline
Posts: 9
Quote msnoshoes Replybullet Posted: 08 Feb 2012 at 3:05am

The error I got is "string lenght is less than 0 or not an integer."

IP IP Logged
mudcat1
Newbie
Newbie
Avatar

Joined: 21 Jul 2008
Online Status: Offline
Posts: 11
Quote mudcat1 Replybullet Posted: 09 Feb 2012 at 8:16am
Try adding a If, The, Else that tests for an empty string which is probably causing the erro.
 
IE.  numbervar endposition:= instr(mid({table.field}, instr({table.field}, '>') +1), '<')-1;
Something like this:
 
If endposition <1 then "No String"
Else endposition;

I hope this helps.

IP IP Logged
msnoshoes
Newbie
Newbie


Joined: 10 Sep 2009
Location: United States
Online Status: Offline
Posts: 9
Quote msnoshoes Replybullet Posted: 13 Feb 2012 at 11:26am
I feel stupid, but I must be doing something wrong.  Do I put the If statement before or after the rest of the formula?
Thanks so much!
IP IP Logged
mudcat1
Newbie
Newbie
Avatar

Joined: 21 Jul 2008
Online Status: Offline
Posts: 11
Quote mudcat1 Replybullet Posted: 13 Feb 2012 at 12:07pm
I think you are looking to make sure that both brackets are there.  If either one is missing and you don't have an escape route, ther report will error.
 
Try something like this:
 
If (INSTR(1,{table.field},'>') > 0 and INSTR(1,{table.field},'<') > 0) then
numbervar endposition:= instr(mid({table.field}, instr({table.field}, '>') +1), '<')-1)<0;
mid({table.field}, instr({table.field}, '>') +1, endposition)
Else 'Bracket Missing';
 
So if either bracket is missing in the string, your report will print the string in the foirmula instead of the error.
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 15 Feb 2012 at 2:21am
Sorry, I didn't account for an empty string. mudcat1 is correct, you need to write something to test if the string is empty then adjust your output for an empty string. Simplest thing I can think of is:


numbervar endposition:= instr(mid({table.field}, instr({table.field}, '>') +1), '<')-1;

if endposition=0
    then ""
//
between these quotes you can put whatever output you want for an
//empty string. I have left it to leave a blank string in this instance
        else
mid({table.field}, instr({table.field}, '>') +1, endposition);




Edited by FrnhtGLI - 15 Feb 2012 at 2:21am
|< /\ '][' ( )
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