Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on

Parsing in Crystal Report

how to extract data before the first blank or space?
6666 OP
64 hhh
in this example, return 6666 . or. 66 in the other one
Avatar of arnold
arnold
Flag of United States of America image

Which version of crystal reports?

You could look at Rtrim/Ltrim

Try string Functions
Avatar of zachvaldez

ASKER

2016
Avatar of Mike McCracken
Mike McCracken

If it always a number you can use VAL to get the value.

Use a formula
Left({YourField}, InStr({YourField, ' ')-1)

mlmcc
Try using rtrim(string) and see what you get.
You can use split on space and get the first element of the array.
You could use substring..

You could add this to the SQL query using SQL related

Using substring charindex or rtrim

The field is being used for sonething else,that you need to convert it to a datatype?
ASKER CERTIFIED SOLUTION
Avatar of Ido Millet
Ido Millet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
 To add to Ido's suggestion, if the field could every be empty (no characters at all, including spaces), the Split function would give you an empty array, and you'd get a subscript error.  You can use the Length function to avoid that:

if Length ({your_field}) > 0 then
  Split({your_field}, " ")[1]
else
  ""

Open in new window

 James
Actually, James suggestion would fail to handle a case where the field has no spaces.
So here's a solution that handles such cases:

local stringvar array myArray := Split({your text field}, " ");
If UBound(myArray) > 0 Then
myArray[1]
ELSE
myArray[0];

Open in new window

 No, it's fine.  If there are no spaces, Split will just give you an array with one element that contains the string (eg. Split ("a", " ") [1] will give you "a").  If you wanted the 2nd or later elements, then you could use UBound to make sure that the array had that many elements.

 Also, there is no 0 element in CR arrays, so your myArray[0] would give you an error.

 James

Because we are going after the 1st (or only) element, James is right.