Solved

Formula to Split a String @ alpha/numeric values

Posted on 2004-08-24
12
1,242 Views
Last Modified: 2008-03-10
Hey experts,

I need a complete crystal formula that can take this string
AAA111
and Split it when the AAA changes to 111 then select either the AAA(0) or 111(1)  to return back to the report.

Big points hope someone can get me a quick answer.
Thanks in advance!



0
Comment
Question by:DTRON04
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 11884412
This formula gives you the 111 portion:     mid('AAA111',instr('AAA111','1'));

This formula gives you the AAA portion:    mid('AAA111',1,len('AAA111')-instr('AAA111','1')+1);


Obviously this is a simple example though - are you asking to split based on any number or will it always be a '1'?

frodoman
0
 
LVL 42

Assisted Solution

by:frodoman
frodoman earned 200 total points
ID: 11884730
This code should handle any value:

stringVar source := 'AAAB1234';  <- replace with {table.field} if you're using a db field for this
numberVar breakPoint := 9999;
numberVar x;

for x := 0 to 9 do
(
if instr(source,cstr(x)) < breakPoint and instr(source,cstr(x)) > 0 then
  breakPoint := instr(source,cstr(x));
);

// Print number
// mid(source,breakPoint);
// Print text
mid(source,1,len(source)-breakPoint+1);

HTH

frodoman
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11884742
can you give more info
0
 
LVL 28

Accepted Solution

by:
bdreed35 earned 300 total points
ID: 11884780
Here is an example of a loop to seperate the string from the number:

stringvar strNumber := "AAA111";
stringvar strText := "";
numbervar x;

While not(numerictext(strNumber[1])) Do
(
    strText := strText + strNumber[1];
    strNumber := mid(strNumber,2);
);

strNumber;

It just returns the number right now but you can add the logic at the end to determine if you want to return the "AAA" or the "111".  It should work for any valid number.  Tell me the logic if you need help.
0
 

Author Comment

by:DTRON04
ID: 11885066
Hey all thanks for all that i think bdreed35 is the closest to what i need

Let me explain some more logic.

Basically the example i gave was for alpha/numeric sepration the characters and lengths can be different.
The constants are this:

the set of letters will always be in the beginning and should never go over holding 5 places, usually 3 to 4.
Then when i hit the numeral that is what i want to split on basically returning the opposite values in 2 seperate formulas.

that is exactly what your doing right  bdreed?

i will try it within the hour i am currently working on something else.
didn't have time get this one on my own, thanks again guys!!
0
 
LVL 42

Expert Comment

by:frodoman
ID: 11885101
Both the formula I provided and the one Brian (bdreed) provided will give you what you want - two different ways to do basically the same thing.

frodoman
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Expert Comment

by:bdreed35
ID: 11885177
Yes, that is exactly what I am doing.

You can create a second formula and reference the other variable so that you can display both values:

@Display_Text

EvaluateAfter({@OtherFormulaName});
stringvar strText;
0
 

Author Comment

by:DTRON04
ID: 11886026
alright guys, thanks!!
Brian your solution worked right out of the box for me.

frodo i will five you 200 for being first.
i understood Brian's style a bit better then yours so that may have been why i kept getting a 0 value or integer error on your solution.

My skills in crystal cyntax are lacking greatly, is there a good book or reference guide i can get to understand the crystal syntax better?
i develope in VB/SQL for web and windows apps and love crystals rapid developement features but the syntax kicks my a** everytime i have to get somewhat complicated with it.
what language is it based on anyway?

regardless, thanks again!
 
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11886057
Book name : Brian Bischof Crystal Reports .NEt programming . Great book I recommend to everyone
Crystal Syntax: C
Regards
Emre
0
 
LVL 42

Expert Comment

by:frodoman
ID: 11886351
The syntax is a hybrid of vb & c.  The keywords are vb-like but the bracketing is c-like.  It is odd, however you can opt to use Basic syntax instead of Crystal.  The Basic syntax is virtually identical to vb.

frodoman
0
 
LVL 28

Expert Comment

by:bdreed35
ID: 11886356
If you are used to VB, you can use Basic syntax to write the formulas.  There is no difference in the amount of speed of either one so it is really based upon your preference.

I recommend leaving the report you have already alone, but you can experiment.  When your in the formula editor, just change the drop down bos in the toolbar from Crystam Syntax to Basic Syntax.
0
 

Author Comment

by:DTRON04
ID: 11886426
thanks i will try to play in just basic and see how i fair, are you guys sitting beside each other or something?
it seems like you were racing to see who could enter key first on those last responses.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now