Solved

Streamline/re-write this please.

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now