Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using substring in crystal report

I have a field in crystal report with the following data:
'605 KL1 - Daniel Steve'
How can i just remove the '605 KL1 - ' and leave the 'Daniel Steve' in the field only? Characters before '-' could be different, i hope the formula would automatically search for the '- ' and then show everything after it.

like image 355
Fire Hand Avatar asked Jun 07 '10 02:06

Fire Hand


People also ask

How do you extract everything to the left of a specific character in a field?

Answer: Use the inStr() function to locate the first asterisk. Then use the Mid() function to grab everything to the left of the asterisk.

How do you find the position of a character in a string in Crystal Reports?

instr = The instr function returns the position of the first occurrence of one string within another. This position is based on a 1 based index of the characters in the string. *For additional information and examples on formula functions, please go to Help, Crystal Reports Help from within the Crystal Reports program.

What is string in Crystal report?

A database field is defined as string data type, contains numeric characters. To perform calculations or summaries such as a sum or an average, the field must be defined as a number data type. How to convert a string field containing numeric characters to a number field in Crystal Reports?


2 Answers

Use Subscript (x[y]) Crystal Syntaxsub

field_name ='605 KL1 - Daniel Steve'

The syntaxis {field_name} [11 to 23]

Result = {field_name} [11 to 23] -> Result = 'Daniel Steve'

Website reference: IBM - Developing Crystal Report

like image 163
user3689238 Avatar answered Oct 14 '22 05:10

user3689238


MID can help here:

MID(my_string, 11) // will print your string from character 11 ("D") forward

And you can combine MID with INSTR if you need the display to be dynamic (of course this will only work if your data have a consistent format):

MID(my_string, (INSTR(my_string, "-") + 2))
like image 39
mechanical_meat Avatar answered Oct 14 '22 03:10

mechanical_meat