2 Replies Latest reply on Jun 19, 2013 6:29 AM by JJJ

# Splitting a string into two new ones

Hello all,

Does anyone have any experience of using formulas to split a single string into multiple strings please?

I'd like to take strings like this:

Joe Bloggs*Residents Services*Finance*Central Services

and put everything between the second to last asterix and the last asterix, into one string

and put everything after the last asterix into another string

so I'd ultimately end up with:

string 1 = 'Finance'

string 2 = 'Central Services'

The number of asterixes in a sentence will vary so I can't do this from the left hand side of the string, only the right hand side...is this even possible?

Any advice would be really appreciated Thanks!!!

• ###### 1. Re: Splitting a string into two new ones

Have you been through the Calculation tutorials.  e.g

http://community.landesk.com/support/docs/DOC-26677

Those are a good place to start.  There are then various BOO web sites where you could look up code snippets, learn how to do general BOO stuff and so on.  If you want get some specific help in the UK on writing this type of stuff for you, then I'm sure the LANDesk consultancy team in Bracknell would be glad to help you with some services.

• ###### 2. Re: Splitting a string into two new ones

To do this within Crystal, create the following in a formula:-

StringVar array values = split( {field}, "*");

if ubound(values) >= 1

then values[1]

else ""

The first line splits the field into an array, dividing the field up by each * it finds.

The second line checks that the array has 1 or more items, if it has it will return the first item in the array, if not it will return an empty string.

You could replace lines 2-4 with values[1], and providing the field always had at least one value it would work - but if it didnt then the formula would error, whereas the if statement protects against the times when the item you want doesn't exist.