?
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
?
310 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 how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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

764 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