Parse string Crystal report

Hello,

I am trying to parse data from a string column in Crystal Reports.

Attached screenshot will show how the data comes from the table. I need to get only the string that starts with "CD%". This number is always 12 characters.

Example I want the output to be
CD0002657601
CD0002560701
CD0002657601
etc..

Please let me know how to get this accomplished. Thank you
CD.PNG
angel7170Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ido MilletProfessor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
It is possible to build formula logic to do this, but it would be easier and faster to use a UFL that adds Regular Expression logic to Crystal functions.

At least one of the 3rd-party UFLs listed at http://kenhamady.com/productlinks/default.html#ufl provides such a function. The formula would then simply be:
uFLRegExpMatch(YourStringColumn, "CD\d{8}");

Open in new window


If you still want tp pursue regular formula logic, please clarify a few points:
a) do all rows contain the target string?  If not, what should be returned?
b) what should happen if a single row contains 2 target strings?
0
angel7170Author Commented:
Thank you but I would like to use a regular formula

a) do all rows contain the target string?  If not, what should be returned? - Not all rows contain the target string. If nothing is found then return NULL

b) what should happen if a single row contains 2 target strings? - A single row will only contain 1 target string.
0
Ido MilletProfessor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
Try something like this:
local stringvar YourStringColumn := "khdsh  sdjfhgfjgf s sjhgfgCD01234567 was removed";
local stringVar result := "" ;
local numbervar i := instr(YourStringColumn, "CD");
While i > 0 do
(
IF Len(YourStringColumn) - i >= 10 Then
(
result := mid(YourStringColumn, i, 10);
IF NOT NumericText(Replace(Replace(Replace(mid(result, 3),".","X"),",","X")," ","X")) Then
(result := "";
i := instr(i+1, YourStringColumn, "CD")
) ELSE
i := 0
);
);
result;

Open in new window

0
mlmccCommented:
If there are no other possible CD% strings in the data, you could use a formula involving SPLIT

Local StringVar Array myStrings;
If InStr({YourString},'CD') > 0 then
(
myStrings := Split({YourString},'CD');
If UBound(myStrings) = 1 then
    'CD' & Left(myStrings[1],10)
Else
    'CD' & Left(myStrings[2],10)
)
Else
    ''

Open in new window


This might also work
Local StringVar Array myStrings;
If InStr({YourString},'CD') > 0 then
(
myStrings := Split({YourString},'CD');
'CD' & Left(myStrings[UBound(myStrings)],10)
)
Else
    ''

Open in new window


mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
angel7170Author Commented:
Both of your solutions worked as expected. thank you very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.