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

replace function causing gap in list 1

Status
Not open for further replies.

BHScripter

Technical User
Aug 26, 2002
159
US
Hi:
I am replacing both a word and a deliminator in a string. If the word is the first word in the string, it is causing a gap at the top of the list. My formula is below, any help would be most appreciated.
dim uamenities as string
if ISNULL({Command.unit_amenities}) or {Command.unit_amenities} = "" then
uamenities = "None"
else
uamenities = ProperCase(Replace ({Command.unit_amenities}, ",", Chr(10)))
uamenities = ProperCase(Replace ({Command.unit_amenities}, "Rent,", "") )
uamenities = ProperCase(Replace ({Command.unit_amenities}, "Rent", ""))
uamenities = ProperCase(Replace (uamenities, ",", Chr(10)) )
end if
formula = uamenities
 
Lets say value for {Command.unit_amenities} is "Rent, gas and water"

Line 1 will get the value from {Command.unit_amenities}, will replace all commas with Chr(10) and will assign the new string to uamenities.
uamenities ="Rent
gas and water"

Line 2 will ignore the result from line 1, will get the value from {Command.unit_amenities}, will replace "Rent," with empty string and will assign the new string to uamenities.
uamenities ="gas and water"

Line 3 will ignore the result from lines 1 and 2 , will get the value from {Command.unit_amenities}, will replace "Rent" with empty string and will assign the new string to uamenities.
uamenities=", gas and water"

Line 4 will replace “,” in uamenities with Chr(10) and that is why there will be an empty space at the beginning

As you can see line 1 and 2 will not do anything because the result will be overwritten later

If your goal I to convert comma separated string to a list you can use Split({Command.unit_amenities},”,”) then loop through the returned array and concatenate the elements + Chr(10) ignoring those you don’t want to see
At the end cut the last Chr(10)

stringVar array Data := Split({Command.unit_amenities},",");
stringVar strOutput :="";
numbervar i;
For i := 1 to Ubound(Data) do
(
if (Data<>"Rent") then
strOutput := strOutput + Trim(Data) +chr(10);
);

if (Mid(strOutput,Length(strOutput)) = Chr(10)) then
strOutput :=Left(strOutput,Length(strOutput)-1);

strOutput;


This formula is in "crystal syntax" , you need to change it if you want to continue with "basic syntax".

Viewer, scheduler and report manager for Crystal reports and SSRS.
Send your report everywhere.
 
Thank you that works beautifully! I love this forum as not only do you help but you explain so I have increased knowledge every time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top