cancel
Showing results for 
Search instead for 
Did you mean: 

removing portion of the text

Former Member
0 Kudos

Hi All,

I have the following table, Full_Name column is the original data and Modified column is from Crystal Report Formula Field. I want to take out 'in Boston', 'in New York', and 'in Los Angeles' from the Full_Name and write it under Modified (as shown in the table). It would be a simple code, I tried it many ways but it's not working. Can someone help me writing the code please. Thanks - Brian

Full_NameModified
John in BostonJohn
Bell in New YorkBell
Tiger in Los AngelesTiger
Rodney in BostonRodney
Graham in BostonGraham
Bill in New YorkBill
Marry in New YorkMarry
Juaida in Los AngelesJuaida
Felton in New YorkFelton
Shawn in Los AngelesShawn

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member203168
Active Participant
0 Kudos

Hi,

Try this code:

Split({Full_Name}, " in ")[1]

--Praveen G

abhilash_kumar
Active Contributor
0 Kudos

Hi Brian,

Try this code:

Split({Full_Name}, " ")[1]

-Abhilash

Former Member
0 Kudos

Hi Abhilash, You and I are almost there. Actually text under Full name column are way bigger than I mentioned. It's like:

Full_Name

John Valley in New York

Lake point Valley in Boston

Southwood Country club Course in Los Angeles

So, What I have to do is: take out  'in New York', 'in Boston', 'in Los Angeles' from each line rather than keeping the first word (the way you showed) only. Can you please help writing the code for that?

Sorry, it was a little confusing in my previous post.

Thanks, Brian.

abhilash_kumar
Active Contributor
0 Kudos

OK. Use this code then:

Replace(Replace(Replace({database_field}, " in New York"), " in Boston"), " in Los Angeles")

-Abhilash

Former Member
0 Kudos

Hi Abhilash, I tried your send one but it's not working. I wrote it as follows:

Replace(Replace(Replace({Modified}, " in New York"), " in Boston"), " in Los Angeles")


Modified is the formula field and Full_Name is the field from Database. Can you please confirm if the above codes are working/right code from your end?

Thanks a bunch.

Brian

abhilash_kumar
Active Contributor
0 Kudos

Shouldn't the formula point to the database field instead of the formula itself?

Something like this:

Replace(Replace(Replace({Full_Name}, " in New York", ""), " in Boston", ""), " in Los Angeles","")


And, I also missed out something in the code. See if this one works.


-Abhilash

Former Member
0 Kudos

GREAT!!! It's working now Abhilash. Thanks for your help.

Brian

Former Member
0 Kudos

Hi Abhilash,

Would bother you one more time. What could be the code for the reverse? I mean if I want to keep only the city name from the list. I mean let's say a formula field called 'City' will extract the text 'New york', 'Boston' and 'Los Angeles' form Full_Name.

Thanks,

Brian

abhilash_kumar
Active Contributor
0 Kudos

That would involve creating a variable that contains the city names and then extracting the names based on the values in the variable.

1) Create a variable that contains city names and place this on the Report Header.

WhilePrintingRecords;

stringvar array city := ["Boston", "New York", "Los Angeles"];

"";

2) Create another formula that extracts the city names from the field on the details section. This goes in the Details section of course:

WhilePrintingRecords;

stringvar array city;

local stringvar temp;

local numbervar i;

for i := 1 to ubound(city) do

(

     If Instr({Full_Name}, city[i]) > 0 then

          temp := city[i]

     else temp := "No City Found";

);

temp;

-Abhilash