zachvaldez
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
6666 OP
64 hhh
in this example, return 6666 . or. 66 in the other one
ASKER
2016
If it always a number you can use VAL to get the value.
Use a formula
Left({YourField}, InStr({YourField, ' ')-1)
mlmcc
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
""
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:
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];
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
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.
You could look at Rtrim/Ltrim
Try string Functions