[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

string functions

OK,

I have this in asp


strPath = "c:\inetpub\wwwroot\test"
Left(strPath,InstrRev(strPath,"\"))

output = "c:\inetpub\wwwroot\"

I need to be able to do this in coldfusion.  Any ideas??

Thanks,
-I remain
0
turbosig
Asked:
turbosig
  • 9
  • 5
  • 4
  • +2
1 Solution
 
VincentPugliaCommented:
Hi,

in javascript:

strPath = "c:\\inetpub\\wwwroot\\test"
ndx = strPath.lastIndexOf('\\')
strPath = strPath.substring(0,ndx)
alert(strPath)

Note the double backslashes "\\"  -- you need to escape them if the str is created manually; if you are getting the str from a path, they are either rendered as "/" or already doubled.

for example
alert("c:\inetpub\wwwroot\test")

Vinny
0
 
DoppyNLCommented:
>> I need to be able to do this in coldfusion.  Any ideas??

reply to that:
>> in javascript:

errmmm, right....
0
 
ZontarCommented:
Try REReplace(path, "\\.+$", "\")

And see here for more about CF RegExps:

http://www-tcsn.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20654057.html
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
turbosigAuthor Commented:
OK, none of these are answering the question.

1st of all NOT javascript.  There HAS to be coldfusion functions that are equivelent to .asp.

Now, regular expressions I do not believe will work because I am only matching a pattern to find a position.

I wan to take any string (this is an example)

c:\inetpub\wwwroot\test

and trim off everything to the right of the last "\" or "/"

Thanks.
0
 
VincentPugliaCommented:
>>There HAS to be coldfusion functions
1) Most people who program in a language have a manual with an appendix of functions, keywords, etc.
2) search the coldfusion forums with google
3) coldfusion allows you to execute javascript

Vinny
0
 
turbosigAuthor Commented:
I actually don't want to use javascript.

I was hoping to get the coldfusion equilelent of the InstrRev function in coldfusion.  Simply stated, I guess that is the question.  

Does coldfusion have an function that correlates with asp's InstrRev function.
0
 
VincentPugliaCommented:
0
 
turbosigAuthor Commented:
Yup, went there.  So I guess it can'tbe done.

Thanks.
0
 
D_M_DCommented:
You can use the following CF Functions in place of your vb functions:

Function               Action                                                                 Example                                  Return
-----------------------------------------------------------------------------------------------------------------------------  
REFIND                 position of a substring in a string                           Refind("ote", "Hotel")                  2
LEFT                    n leftmost characters                                         Left("The White cat", 3)                 "The"


Use CFLOOP to loop thru the string
Use the ReFind Function to find the  "/" or "\" - return a postion like the Instr Function

Use the CFIF to test for the last instance of what you are searching for.  
Use the LeftFunction to grab everything to the Left of the  last "\" or "/"

D_M_D
0
 
turbosigAuthor Commented:
Thanks D_M_D, that was the most relevent solution.  After developing in asp for so long, I am finding some basics that I really miss from vb (although coldfusion has a lot of positives).

Thanks
-I remain
0
 
VincentPugliaCommented:
And it only took you 27+ hours to get a solution you could have found on your own by searching google :)

Vinny
0
 
turbosigAuthor Commented:
Vinny,

1. At first I wanted a solution (and NOT javascript as I stated).

2. D_M_D was the only one who actually SHOWED me a NON javascript solution.

3. I did go to google, AND to Macromedia's live docs and searched for a coldfusion version of the InstrRev functions - To which I did not find one.  I had already been there a dozen times

For your labor I will give you the points as well (look for the question).  I am not here to make enemies, just solve problems.  Not add to them by arguing.

-I remain
0
 
VincentPugliaCommented:
Hi turbosig,

  I don't want points; they buy me neither coffee nor cigarettes.  I just believe your question could have been answered by yourself -- either by looking through a manual or book, or searching through the online resources -- I saw the refind and trim methods and knew they would be what you needed.  But, my time is at least worth as much to me as yours is to you. I work a lot of boards; in all of them, I tell people to help themselves first.

Vinny
0
 
turbosigAuthor Commented:
Well I appreciate that.  My idea was if I did everything myself, there would be no need for this board.  I have a project I am creating and can better utilize my time doing the things I do know how to do.  I am new to coldfusion, but have a project someone wants done.  So that was the reason behind that.  I am sure as I go along, I will find ways to do things here and there.

Take the points, the question is already there.
0
 
ZontarCommented:
> Now, regular expressions I do not believe will work because I am only matching a pattern to find a position.

But this is *exactly* what regular expressions do! "\\.+$" = "backslash plus 1 or more characters at the end of a string".

> D_M_D was the only one who actually SHOWED me a NON javascript solution.

Ahem. I showed you a CF function. Not JS.

I don't really care about points, either, and CF's not my forte anyway, but seeing these statements sort of irked me.

> I work a lot of boards; in all of them, I tell people to help themselves first.

So do I, and my experience is that telling people to RTFM is not very helpful or encouraging. Okay, some of them need are expecting everything to be handed to them on a silver platter and need to be told that, but a lot of them really are trying and just need a hint or two to get going in the right direction.
0
 
turbosigAuthor Commented:
Zontar,

I apologize.  your explaination above clears up how that works.

It pays to fight back ;)

-- You will also get points (assuming I still have any to give out.)  

I have never been here so much in my life.  I am usually on the asp/vbscript boards.  I have this coldfusion program to write - To show SOME sort of knowledge for a new position.

Thanks.

Look for your points here.

-I remain
0
 
turbosigAuthor Commented:
Zontar,
Actually I just tried this:

<cfoutput>
<cfset path2="c:\inetpub\wwwroot\whatup">
<cfset MyOutput=#REReplace(path2, "\\.+$", "\")#>
#MyOutput#
</cfoutput>

What I have : c:\inetpub\wwwroot\whatup
What I got was : c:\
What I wanted was : c:\inetpub\wwwroot\

So actually it doesn't really do what I wanted.
0
 
ZontarCommented:
Okay, well, then RE's in CF are "greedy", then.

"\\[^\\]+$" should work. (= "a backslash followed by one or more non-backslash characters at the end of the string".)

I originally starting coming around again with the idea of boning up some more on XSLT, but I keep getting sidetracked. ;-)
0
 
turbosigAuthor Commented:
PERFECT...

Now go get your points...

That is EXACTLY what I was looking for.
0
 
ZontarCommented:
Hey, thanks!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 9
  • 5
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now