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
Solved

string functions

Posted on 2003-11-06
20
557 Views
Last Modified: 2013-12-16
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
Comment
Question by:turbosig
  • 9
  • 5
  • 4
  • +2
20 Comments
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9698929
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
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9699950
>> I need to be able to do this in coldfusion.  Any ideas??

reply to that:
>> in javascript:

errmmm, right....
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9700117
Try REReplace(path, "\\.+$", "\")

And see here for more about CF RegExps:

http://www-tcsn.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20654057.html
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Author Comment

by:turbosig
ID: 9700645
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9701120
>>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
 
LVL 2

Author Comment

by:turbosig
ID: 9701661
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9702060
0
 
LVL 2

Author Comment

by:turbosig
ID: 9702332
Yup, went there.  So I guess it can'tbe done.

Thanks.
0
 
LVL 10

Accepted Solution

by:
D_M_D earned 50 total points
ID: 9702907
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
 
LVL 2

Author Comment

by:turbosig
ID: 9703097
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9703127
And it only took you 27+ hours to get a solution you could have found on your own by searching google :)

Vinny
0
 
LVL 2

Author Comment

by:turbosig
ID: 9703159
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9703221
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
 
LVL 2

Author Comment

by:turbosig
ID: 9703258
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
 
LVL 11

Expert Comment

by:Zontar
ID: 9703391
> 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
 
LVL 2

Author Comment

by:turbosig
ID: 9703443
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
 
LVL 2

Author Comment

by:turbosig
ID: 9703507
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
 
LVL 11

Expert Comment

by:Zontar
ID: 9703679
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
 
LVL 2

Author Comment

by:turbosig
ID: 9703712
PERFECT...

Now go get your points...

That is EXACTLY what I was looking for.
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9705518
Hey, thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to dynamically set the form action using jQuery.

840 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