cancel
Showing results for 
Search instead for 
Did you mean: 

formula for a field in the Crystal report 2014

Former Member
0 Kudos
51

Hi experts,

I am using CR 2014.

Am trying to create a formula in the Cyrstal report for a field as below.

nnm1.SeriesName   = "CHN-16"

now, i want the formula to separate the  nnm1.seriesname as above by "-". 

for example : i want only CHN instead of CHN-16

Thanks in advance,

REgards,

Dwaraka

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Dwarka,

You can also refer to below code apart from what Abhilash suggested .

If Instr({nnm1.SeriesName},"-")<>0 Then

Mid({nnm1.SeriesName},1,Instr({nnm1.SeriesName},"-")-1)

Else

{nnm1.SeriesName};


Regards

Niraj

Former Member
0 Kudos

Hi expert,

there is small change in my requirement,

I want split for alpha and numeric.  i have CHN16-17 as doc series name, whereas i want to print only CHN .

can we able to do this ?

Thanks in advance,

Dwaraka

abhilash_kumar
Active Contributor
0 Kudos

Hi Dwaraka,

Assuming the string always starts with letters, you can use this:

Local stringvar s;

Local numbervar i;

For i := 1 to Len({string field}) do

(

If {string field} [i] in [ 'A' to 'Z'] then

s := s + {string field} [i]

Else

Exit for;

);

s;

-Abhilash

abhilash_kumar
Active Contributor
0 Kudos

Please change the code to:

Local stringvar s;

Local numbervar i;

For i := 1 to Len(m) do

(

     If m [i] in [ 'A' to 'Z'] then

          s := s + m [i]

     Else

     (

          Exit for;

          '';

     );

);

s;

-Abhilash

Answers (1)

Answers (1)

abhilash_kumar
Active Contributor
0 Kudos

Hi Dwaraka,

Create a formula with this code:

Split({Database_field}, '-')[1]

-Abhilash