Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splitting a field into 3

Status
Not open for further replies.

Paul1981

IS-IT--Management
Joined
Jun 30, 2006
Messages
36
Location
GB

Hi I have a field "05-GAMES-06", how do I split this into 3 seperate fields "05", "GAMES" and "06"

Thank you
 
Try:

split({table.field},"-")[1]

Change the number to 2 or 3 for the other two fields. This assumes that the field always contains three elements separated by "-".

-LB
 

Sorry, that didnt work :(

not all the fields are in this format.... which does make it tricky, but just need it working for this format for now.

Is there away of telling crystal when to split (ie after 2 characters)??
 
What error message did you get?

Please provide samples that include the variations in the field.

-LB
 
Try:

whileprintingrecords;
stringvar array MyValues := split({table.field},"-");

Then create your display formulas as:

whileprintingrecords;
stringvar array MyValues;
If ubound(MyValues) > 0 then
MyValues[1]
else
{table.field}

whileprintingrecords;
stringvar array MyValues;
If ubound(MyValues) > 1 then
MyValues[2]

whileprintingrecords;
stringvar array MyValues;
If ubound(MyValues) > 2 then
MyValues[3]

-k
 

I got an error message saying 'A subscript must be between 1 and the size of the array'.

Other than '06-GAMES-06'. The field can include random words, theys will be reoved at a later stage.
 

I got an error message saying 'A subscript must be between 1 and the size of the array'.

Other than '06-GAMES-06'. The field can include random words, theys will be removed at a later stage.

thanks

Paul
 
You have to use the introductory clause. You can write each formula like:

//{@field1}:
stringvar array x := split({table.field},"-");
if ubound(x) >= 1 then
x[1] else
{table.field}

//{@field2}:
stringvar array x := split({table.field},"-");
if ubound(x) >= 2 then
x[2] else
{table.field}

//{@field3}:
stringvar array x := split({table.field},"-");
if ubound(x) >= 3 then
x[3] else
{table.field}

-LB
 
If you'd used my formula you can't get that error, it checks for the size first, so post what you tried and where rather than stating that you get an error.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top