[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Coldfusion How can I trim my output to not show the first 11 or 7 characters?

Posted on 2014-03-26
4
Medium Priority
?
312 Views
Last Modified: 2014-03-26
My search results look like this:

Mainserver\Spongebob

How can I trim the first 11 characters and have the output look like:

Spongebob

I'm using Replace:
Replace(updateby,"Mainserver\","")

Problem: Some entries have "Mainserver\" or "Server\"
How can I replace if "Mainserver\" or "Server\"?
0
Comment
Question by:DJPr0
[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
 
LVL 52

Expert Comment

by:_agx_
ID: 39956887
If the value always contains a "\", try using list functions instead. Does it always have 2 parts ie Like "Mainserver" and "Spongebob" ? If so you could use listLast:

     ListLast("Mainserver\Spongebob", "\")

EDIT:  Otherwise, try getToken():

     <!--- get the 2nd piece of "\" delimited string ie "SecondElement"
           "FirstElement\SecondElement\ThirdElement...."

            If the list only has one element, this will return an empty string ""
     --->
     getToken("Mainserver\Spongebob", 2, "\")
0
 

Author Comment

by:DJPr0
ID: 39957032
Not all values have 2 parts, could be:

Mainserver\Spongebob
Server\Spongebob
Spongebob

Can we have 2 Replace statements or:

Replace(updateby,("Mainserver\"or"Server"),"")
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 39957080
If you always want to omit the 1st part, just do an if/else:

      <cfset str = "Mainserver\SpongeBob">
      <cfif listLen(str, "\") lte 1>
           <!--- show string as is --->
            #str#
      <cfelse>
           <!--- remove 1st element, whatever it is --->
            #listRest(str, "\")#
      </cfif>

If you want to do a plain replace, you'll need to call the function twice. If the case can vary, use the case insensitive version:

          ReplaceNoCase(ReplaceNoCase(updateBy, "MainServer", ""), "Server", "")
0
 

Author Closing Comment

by:DJPr0
ID: 39957423
Thanks _agx_!
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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