cancel
Showing results for 
Search instead for 
Did you mean: 

Convert string manipulation formula from excel to CR

Former Member
0 Kudos

Hello everyone,

I have a formula that I am trying to convert to crystal syntax. In excel formula works. Basically, it outputs the string between two hyphen characters.

XXXXX-WHITE-1 >>>>>>> formula >>>>>>>> WHITE

Here is the formula that I use in excel:

=MID(A1,FIND("-",A1)+1,(FIND("-",A1,FIND("-",A1)+1))-FIND("-",A1)-1)

How can I convert this formula into something that crystal reports understand?

P.S. A1 is going to be ItemCode.

Any help is appreciated!

Accepted Solutions (1)

Accepted Solutions (1)

DellSC
Active Contributor
0 Kudos

Replace the "FIND" with "InStr" and switch the parameters around.  So, it might look like this:

MID({MyField},InStr({MyField},"-")+1,(InStr({MyField},"-",InStr({MyField},"-")+1))-InStr({MyField},"-")-1)

-Dell

Former Member
0 Kudos

I have tried that formula already and it did not work.

This is the error I get:

String length is less than 0 or not an integer.

DellSC
Active Contributor
0 Kudos

Try this:

If not IsNull({MyField}) and InStr({MyField}, "-") > 0 then

MID({MyField},InStr({MyField},"-")+1,(InStr({MyField},"-",InStr({MyField},"-")+1))-InStr({MyField},"-")-1)

-Dell

Former Member
0 Kudos

I still get the same error.

abhilash_kumar
Active Contributor
0 Kudos

Hi Korhan,

Try this please:

local stringvar s := {A1};

local stringvar temp := Mid(s,Instr(s,'-')+1);

if instr(temp,'-') > 0 then

    Mid(temp,1,Instr(temp,'-')-1);

-Abhilash

Former Member
0 Kudos

This works. Thank you.

Answers (0)