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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Crystal Arrays/Split Function 2

Status
Not open for further replies.

snazzyCrunch

Technical User
Apr 18, 2002
26
0
0
US
Hi,

i'm using CR8.5. I have a formula named @custName. the fields in the database sometimes contain extra characters I don't want to display. i'm trying to use the split function to split the field with a delimiter of " ", and take the first field.

Here's my code (using Crystal Syntax):

if ({CUSTOMER_NAME} = "funkyCustomer")
then
split({SERVICE_NAME}, " ")
else
{SERVICE_NAME}

Thus, if the SERVICE_NAME field contained "CSC2311 C++ Programming", then I would like to grab everything up to the space, "CSC2311".

Thanks in advance. I don't have the help installed and there is nothing in the manual about the split function.

snazzyC.
[morning]
 
if ({CUSTOMER_NAME} = "funkyCustomer")
then
split({SERVICE_NAME}, " ")[1]
else
{SERVICE_NAME}

Note: This will not work if ({SERVICE_NAME} is = blank. If this can happen you will have to add a check for this condition.
 
Interesting approach, another is:

left(trim({Customer Name}),instr(trim({Customer Name})," "))

Which avoids using arrays, which would have a performance cost.

I added a TRIM to it to avoid even funkier customers...

In your example, if the address starts with a space, the first element of the array will be blank, if you know this space condition doesn't exist, omit the trim() function.

-k kai@informeddatadecisions.com
 
Thanks synapsevampire and JoeCrystal,

Quick question to synapsevampire. Just so I understand this fully, does the function inStr return the first index of the occuring "string".

left(trim({Customer Name}),instr(trim({Customer Name})," "))

So in the above line you are getting a substring of {Customer_Name} starting from the left up to and not including the first index of a " "?

Both you're examples worked great. I appreciate the help!

snazzyC.
[afro]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top