Solved

Streamline/re-write this please.

Posted on 2006-06-20
4
180 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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