1

i'm using ItemName field in a Crystal Report. The field contains the item name and dimensions: -

Egg Pot & Saucer 47x41cm

I wish to suppress the dimension details, leaving just the text part of the string. I'm looking for a set of functions that could create a formula in Crystal to do this. The issue is the there are many different syntax for the dimension part: -

65x47x30cm or 43cm or 47x41cm

The constant is that they all start with a Numeric.

1 Answers1

1

I think using a combination of crystals string functions (Instr,Left,Length,Replace etc) you should be able to accomplish this.

What have you tried so far?

would any of the required info (Egg Pot & Saucer) contain numbers?

if not, find the first occurrence of a number using a loop and isNumeric

then use LEFT to return everything before that number.

Local StringVar f := {Command.ItemName} ;
local Numbervar L := length(f) ;
Local Numbervar i ;
Local StringVar s ;
for i := 1 to L do
(
( If IsNumeric(f[i]) then exit for )
);
Left ({Command.CardName},i -1)

updated with additional condition:

Local StringVar f := {Command.CardName} ;
local Numbervar L := length(f) ;
Local Numbervar i ;
Local StringVar OutPut ;


If {Command.CardName} like "* Set *"  Then 
f
else
(for i := 1 to L do
( If IsNumeric(f[i]) then exit for);
 OutPut:= Left({Command.CardName},i -1);)

Praxiom
  • 578
  • 1
  • 8
  • 21
  • 1
    Ok. Just struggling with the Syntax. As the number could be anything from 1-9 do I need to look for each occurrence as a separate line, nested? Also how to get the InStr function to ID the first of any number it finds rather than specifying a character? – Digital_Speed Feb 18 '20 at 07:02
  • Hi, i have edited my Answer to include an example. Let me know if you need anything else :) – Praxiom Feb 18 '20 at 09:36
  • 1
    This works perfectly. Well beyond my ability so thanks heaps. One extra thing if I can ask. Some items have the description of "Egg Pot & Saucers Set 4". Is there a way of editing your script to include numbers AFTER the work "Set"? – Digital_Speed Feb 18 '20 at 10:49
  • That's great, glad to help :) if you could mark my answer as correct that would be fantastic. I will have a look at your 'Set' issue as well. – Praxiom Feb 18 '20 at 10:56
  • 1
    Thanks again. If you could think about that 'Set 2' issue it would be great. – Digital_Speed Feb 19 '20 at 10:56
  • 1
    Again! Just fantastic. Your skills have saved me hours on unnecessary work. I hope to be ale to return the favour one day. – Digital_Speed Feb 19 '20 at 22:55
  • No problem at all :) if you could upvote my answer and comments that would be great :) – Praxiom Feb 20 '20 at 12:13