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

Split function

Status
Not open for further replies.

rschkrt

MIS
Apr 24, 2002
13
US
I have data coming to crystal report with "&" sign.

Example &Tom&Bill&Sam

How can I get rid of the "&" sign? Someone suggested using the split function, but I couldn't get it to work.

Thank you
 
If you just want the string to read: Tom Bill Sam
then the replace function should do the trick:

replace({table.names},"&"," ")

If you want each name to be a separate field, then the split function is what you need.

-LB
 
I need each name to be a separate field. How do I use split function? I'm getting a error.


Thank you.
 
Split doesn't make it a separate field, it places it into an array.

Nothing will make it a separate field in Crystal.

Perhaps if you shared what you intend to do with it someone might better help you.

One method is to use a formula like:

join(split({table.field},"&"),chr(13))

Make sure to format the field to can grow.

Alternatively you might use LB's method:

replace({table.names},"&",chr(13))

-k
 
I need each number to be a separate field. Maybe this example will help.

Example 1&2&3&4

if = 1 then a "x" goes into Box 1
if = 2 then a "x" goes into Box 2
etc.

Thank you
 
You will need separate formulas for each of these "Boxes".

Here's an example:

whileprintingrecords;
stringvar array MyString := split("1&2&3&4","&");
numbervar array MyValues [ubound(MyString)];
numbervar X;
for x := 1 to ubound(MyString) do(
MyValues[x] := val(mystring[x])
);

Later formulas used for eacvh box might include something like:
whileprintingrecords;
numbervar array MyValues;
if 1 in myvalues then
1

-k
 
I guess I used the wrong terminology, but I think you could treat the array elements as separate "fields" if you wrote a separate formula for each, such as:

{@split1} for the first array element:

Whileprintingrecords;
stringvar array Names := split({table.names},"&");
Names [1];

{@split2} for the second array element:

Whileprintingrecords;
stringvar array Names := split({table.names},"&");
Names [2];

{@split3} for the third array element:

Whileprintingrecords;
stringvar array Names := split({table.names},"&");
Names [3];

But your example suggests that what you need is the ability to examine a string for the presence of a specific element and then record the result in a box. Maybe what you need is the instring function:

if instr({table.names},"Tom") > 0 then X //formula to place in Box 1

if instr({table.names},"Bill") > 0 then X//formula for Box 2, etc.

Not sure if this is what you're looking for though.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top