Solved

Streamline/re-write this please.

Posted on 2006-06-20
4
182 Views
Last Modified: 2013-12-24
var1 = Replace(Session.WhoInvolvedVisitor, "Type Name followed by <Enter Key> for multiple", "", "All")
var2 = Replace(var1, "chr(10)", ":", "All")
var3 = Replace(var2, ",", ":", "All")
var4 = Replace(var3, "::", ":", "All")
var5 = Trim(var4);

Basicly I want to remove "Type Name followed by <Enter Key> for multiple" from the string
replace return characters with colon
replace commas with colon
and then make sure I don't have doubled up colons
and make sure there is no spaces at beginning or end of string

Is there a cleaner way to do this? I am currently doing it like this but it is ugly:

Trim(Replace(Replace(Replace(Replace(Session.WhoInvolvedVisitor, "Type Name followed by <Enter Key> for multiple", "", "All"), "chr(10)", ":", "All"), ",", ":", "All"), "::", ":", "All"));

Whats the best way to do this?
0
Comment
Question by:max0davis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:max0davis
ID: 16947407
Sorry.. mistyped that...

wivr1 = Replace(WhoInvolvedVisitor, "Type Name followed by <Enter Key> for multiple", "", "All");
wivr2 = Replace(wivr1,chr(10),":","All");
wivr3 = Replace(wivr2,",",":","All");
wivr4 = Replace(wivr3,"::",":","All");
wivr5 = Trim(wivr4);

chr(10) has no quotes around it.

Also.. I noticed that mine can end up with the list starting with a colon.. which I don't want. It can also end up with a space in the list which is alright but I would prefer it didn't.. for example "Donald Duck:Mickey Mouse: Pluto".
0
 
LVL 7

Accepted Solution

by:
aseusainc earned 500 total points
ID: 16947516
You could use replacelist, but even that is going to get a little crazy.  Theres nothing wrong with breaking it out into steps, no matter how you handle it, the amount of processing is going to wind up being about the same.  One thing I would change that will help a bit is to not use a new variable each time.

Then, loop over the colon delimited list and trim each element to a temp list, then pass it back as the main variable again.

<cfset wivr1 = Replace(wivr1, "Type Name followed by <Enter Key> for multiple", "", "All")>
<cfset wivr1 = Replace(wivr1,chr(10),":","All")>
<cfset wivr1 = Replace(wivr1,",",":","All")>
<cfset wivr1 = Replace(wivr1,"::",":","All")>
<cfset finallist="">
<cfloop index="x" list="#wivr1#" delimiters=":">
  <cfset finallist=listappend(finallist,trim(x),":")>
</cfloop>
<cfset wivr1 = finallist>
0
 
LVL 7

Expert Comment

by:aseusainc
ID: 16947526
Oh, also forgot to mention, that the step that trims out the spaces will also, as a byproduct, dump a leading colon.

So ":Donald Duck:Mickey Mouse: Pluto" would end up as "Donald Duck:Mickey Mouse:Pluto"
0
 

Author Comment

by:max0davis
ID: 16953975
How the code ended up:

function listLoop(myList, bodyFunction) {
  var a = listToArray(myList, ":");
  var i = "";
  for (i = 1; i LTE arrayLen(a); i = i + 1) bodyFunction(a[i]);
}

if(IsDefined("whoInvolvedVisitor") and whoInvolvedVisitor neq "") {
  wivr1 = Trim(whoInvolvedVisitor);
  wivr1 = Replace(wivr1, "Type Name followed by <Enter Key> for multiple", "", "All");
  wivr1 = Replace(wivr1,chr(10),":","All");
  wivr1 = Replace(wivr1,",",":","All");
  wivr1 = Replace(wivr1,"::",":","All");
  finallist = "";
  function loopBody(item) {
    finallist=listappend(finallist,trim(item),":");
  }
  listLoop("#wivr1#", loopBody);
  Session.whoInvolvedVisitor = finallist;
}
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question