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

Splitting/Extracting a string into two parts 2

Status
Not open for further replies.

dblady

MIS
Jul 27, 2009
12
0
0
I'm fairly new to crystal. i have a string text that shows changes to an email field in the following format:

customer.EMAIL: before@abc.org -> after@abcdefg.net

I want to be able to extract into two fields like this(stripping everything but the actual email):

[field1] before@abc.org
[field2] after@abcdefg.net

The string will be in one of the following formats:
[1]customer.EMAIL: before@abc.org ->
[2]customer.EMAIL: before@abc.org -> after@abcdefg.net
[3]customer.EMAIL: -> after@abcdefg.net

expected result1- [field1] before@abc.org [field2]blank
expected result2- [field1] before@abc.org [field2] after@abcdefg.net
expected result3- [field1]blank [field2] after@abcdefg.net
Any help is appreciated
 
I wonder if split will work.. I assume it will but I have never used -> as a delimiter

the following should return the before add..... an identical formula using add := x[2]; should return after add


localstringvar array x;
localstringvar add;
split(customer.EMAIL,"->");
add:= x[1];
add

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
Thanks for your help...I've put in the formula

stringvar array x;
stringvar add;
split({Name_Log.LOG_TEXT},"->");
add:= x[1];
add

I get an error: A subscript must be between 1 and the size of the array
 
Hi,
It looks like it does not see -> as a single character delimiter, try:

stringvar array x;
stringvar add;

split({Name_Log.LOG_TEXT},"-");
add:= x[1];
add

and

stringvar array x;
stringvar add2;
split({Name_Log.LOG_TEXT},">");
add:= x[2];
add2



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Hi,
OOPS, in the second formula in my post the
add:= x[2];
should , of course have been, add2:= x[2];




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
You didn't set the array to equal the split. It should be set up like this:

stringvar array x := split({table.string},"->");
stringvar field1 := x[1]; //to display field1 or
stringvar field2 := x[2]; //to display field2

This assumes there is always a "->" in the field and therefore always two elements in the array, even if one of them is a blank.

-LB
 
Hi All,

Thanks for your help. lbass you gave me the missing link! I finally got the results I wanted with the following:

formula1=before
stringvar array x;
stringvar array x := split({Name_Log.LOG_TEXT},"->");
stringvar field1 := x[1]; //to display field1 orstringvar
stringvar field2 := x[2]; //to display field2
stringvar add;
split({Name_Log.LOG_TEXT},"->");
add:= x[1];
add;

formula2=after
stringvar array x;
stringvar array x := split({Name_Log.LOG_TEXT},"->");
stringvar field1 := x[1]; //to display field1 orstringvar
stringvar field2 := x[2]; //to display field2
stringvar add;
split({Name_Log.LOG_TEXT},"->");
add:= x[2];
add;

I cannot thank you all enough! Very much appreciated!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top