Find and remove a trailing slash from a path - brain fade time

525 views
Skip to first unread message

Mike Kear

unread,
Dec 6, 2006, 12:21:41 AM12/6/06
to cfau...@googlegroups.com
I'm having a brain fade .... i know i've done this before but can't
remember how I did it ..

I am programmatically getting the path to the root of the site, and I
want to make sure that if the last character in the path is a slash
(\) that it's removed. That's cos when i combine the root path
vaiable with other variables i want to make sure there is only a
single \ anywhere.

I have this in my application.cfm:

<cfset temprootpath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
which gives me something like

c:\inetpub\wwwroot\

so how to remove the trailing slash?


--
Cheers
Mike Kear
Windsor, NSW, Australia
Adobe Certified Advanced ColdFusion Developer
AFP Webworks
http://afpwebworks.com
ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month

Andrew Scott

unread,
Dec 6, 2006, 12:24:23 AM12/6/06
to cfau...@googlegroups.com
Mike

<cfif string.endsWith('\')>
<cfset string = left(string, Len(string) - 1 ) />
</cfif>

Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613 8676 4223
Mobile: 0404 998 273

Scott Thornton

unread,
Dec 6, 2006, 12:30:36 AM12/6/06
to cfau...@googlegroups.com
endsWidth() ???

That is a fucntion that can't be found in my CF MX 6.1 manual.

>>> andrew...@aegeon.com.au 06/12/2006 4:24 pm >>>

Bruce Trevarthen (B2 Limited)

unread,
Dec 6, 2006, 12:33:08 AM12/6/06
to cfau...@googlegroups.com
Arh, CF6

Use this instead...

<cfif right(string,1) is '/'>


<cfset string = left(string, Len(string) - 1 ) />
</cfif>

Bruce

Andrew Scott

unread,
Dec 6, 2006, 12:31:52 AM12/6/06
to cfau...@googlegroups.com
Scott,

And nor will you either, if you think about it CF sees that as a string and
Java has the method endsWith() so you can leverage of this little trick with
great uses:-)

Joel Cass

unread,
Dec 6, 2006, 12:36:59 AM12/6/06
to cfau...@googlegroups.com
What? there's a manual?

<cfif right(string, 1) EQ "/">
....
</cfif>

-----Original Message-----
From: cfau...@googlegroups.com [mailto:cfau...@googlegroups.com]On
Behalf Of Scott Thornton
Sent: Wednesday, 6 December 2006 4:31 PM
To: cfau...@googlegroups.com
Subject: [cfaussie] Find and remove a trailing slash from a path - brain
fade time

Mike Kear

unread,
Dec 6, 2006, 12:40:39 AM12/6/06
to cfau...@googlegroups.com
Thats not how i did it before, but thats FAR more elegant. Thanks!

I'm assuming endsWith() is a java string function is it? Where can
i find a list of all these functions? I ought to know more about
them.

Cheers
Mike Kear
Windsor, NSW, Australia
Adobe Certified Advanced ColdFusion Developer
AFP Webworks
http://afpwebworks.com
ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month

Andrew Scott

unread,
Dec 6, 2006, 12:42:36 AM12/6/06
to cfau...@googlegroups.com
Yes Mike it is, the best place is java.sun.com and look at the api, or you
could always go looking into the class source files themselves?

Robin Hilliard

unread,
Dec 6, 2006, 4:16:31 AM12/6/06
to cfau...@googlegroups.com
path = reReplace(path,"/$","");

Robin

Mike Kear

unread,
Dec 6, 2006, 4:45:24 AM12/6/06
to cfau...@googlegroups.com
AH! That's the solution I was trying to recall. Thanks Robin.

But I do think that Andrew's java answer was really cool.

Cheers
Mike Kear
Windsor, NSW, Australia
Adobe Certified Advanced ColdFusion Developer
AFP Webworks
http://afpwebworks.com
ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month

grant

unread,
Dec 6, 2006, 6:49:47 AM12/6/06
to cfau...@googlegroups.com
if we were on expertsexchange robin would get the points.

Robin Hilliard

unread,
Dec 6, 2006, 7:14:53 AM12/6/06
to cfau...@googlegroups.com
On 06/12/2006, at 8:45 PM, Mike Kear wrote:
> But I do think that Andrew's java answer was really cool.


I agree. There are lots of interesting undocumented methods hanging
around in CFML - For instance application.getApplicationSettings()
that I blogged about back in 2005:

http://www.rocketboots.com.au/blog/index.cfm?
mode=entry&entry=8A1C48F5-E081-51EF-A7AF8C312529DABA

Here's a script ("Java Eye for the CF Guy"?) that lists some of the
methods hidden away in common-garden CFML things:

<cfapplication name="test" sessionmanagement="true">
<cfscript>
function hiddenMethods(class) {
writeOutput("<h1>Class: " & class.toString() & "</h1><br>");
aMethods = class.getMethods();
for (i = arrayLen(aMethods); i gt 0; i = i - 1)
writeOutput(aMethods[i].toString() & "<br>");
}

// String
s = "hello";
hiddenMethods(s.getClass());

// Array
hiddenMethods(arrayNew(1).getClass());

// XML
hiddenMethods(xmlNew().getClass());

// Struct
hiddenMethods(structNew().getClass());

// Application
hiddenMethods(application.getClass());

// Session
hiddenMethods(session.getClass());

// Template
hiddenMethods(getClass());

// Component
function getClassFromInsideComponent() {
return getClass();
}
instance = createObject("component","WEB-INF.cftags.component");
instance.getClassFromInsideComponent = getClassFromInsideComponent;
hiddenMethods(instance.getClassFromInsideComponent());

</cfscript>

As always, use undocumented methods at your own risk :-)

______________

Robin Hilliard
Director - RocketBoots Pty Ltd
Consulting . Recruitment . Software Licensing . Training
http://www.rocketboots.com.au

For schedule/availability call Pamela Higgins:
w +61 7 5451 0362
m +61 419 677 151
f +61 3 9923 6261
e p...@rocketboots.com.au

or Direct:
m +61 418 414 341
e ro...@rocketboots.com.au

Reply all
Reply to author
Forward
0 new messages