Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Streamline/re-write this please.

Posted on 2006-06-20
4
Medium Priority
?
195 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 2000 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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

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…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 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