Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Extracting only certain words from a string Post Reply Post New Topic
Author Message
joverdorff
Newbie
Newbie


Joined: 10 Sep 2009
Online Status: Offline
Posts: 9
Quote joverdorff Replybullet Topic: Extracting only certain words from a string
     Posted: 11 Sep 2009 at 4:33am
Let's say I have an alphanumeric string X amount of characters long and I want to extract 6 or 7 words from within that string. How do I code CR to search for key words to find the beginning of the word I want and proceed until the occurrence of another key word, extracting everything in between.

For example. Let's say my data field is, "The quick red fox jumped over the lazy brown dog" and I only want "red fox", "jumped", "quick" and "brown dog" How can I make that happen?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 Sep 2009 at 6:44am
hopefully the list isn't long, you could try something like:
local numbervar iIndex;
local stringvar displayMe;
 
iIndex := instr({table.field}, "red fox");
if iIndex > 0 then
 displayMe := mid({table.field}, iIndex, len("red fox");
 
 
this should give you the gist of how to do what you are after.  instr to find the starting point of the string and len to figure out the how many characters to use.
 
to go between 2 set numbers like from quick to the end of jumped, I would try:
local numbervar iStart;
local numbevar iEnd;
 
iStart := instr({table.field}, "quick");
if iStart > 0 then (
 iEnd := instr({table.field}, "jumped");
 mid({table.field}, iStart, iEnd + len("jumped") - iStart + 1 
 
HTH
IP IP Logged
joverdorff
Newbie
Newbie


Joined: 10 Sep 2009
Online Status: Offline
Posts: 9
Quote joverdorff Replybullet Posted: 15 Sep 2009 at 7:00am
Thank you so much for your response! I think it will get me headed in the right direction. After reading my somewhat simplistic question and digesting your very helpful reply, I realized it's a bit more complicated - BUT - as you mentioned, it should be the kickoff point that will give me the start I need.

Thank you again!
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