Extracting part of a string to a specific character in Crystal Reports

Hi there,

While creating a crystal report i was getting values against a field like "ABCD-EF" and i needed the string before the "-" character.

I use the mid() function to obtained my required result. This function requires 3 parameters.

1st:    string to which you need to operate on
2nd:   start point of string (here StartPoint start from 1 not 0, 0 will result in an error).
3rd:    length of the string you want to extract

Add the below code to the Display String property:

if instr({ORDERSTATUS.MODL},'-')>0

instr(string to operate, character till you stopped) => This method will return the length of the string till '-' character, so you would get "ABCD-".
That is why you need to do '-1' at the end.

Happy coding!

Popular Posts