Fire Hand
Fire Hand

Reputation: 26416

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.

Upvotes: 9

Views: 93894

Answers (3)

lwin
lwin

Reputation: 4460

I think u can also use Split function like that

Split ({field_name},"-")[2]

But if you want to use split function,u must make sure delimiter exist in the string or add some condition to prevent runtime error. Split function returns an array but it's doesn't start with zero. Its mean [1] is first room and [2] is second room.

Upvotes: 2

user3689238
user3689238

Reputation: 81

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

Upvotes: 7

mechanical_meat
mechanical_meat

Reputation: 169504

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))

Upvotes: 18

Related Questions