Solved

string functions

Posted on 2003-11-06
20
554 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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
Try REReplace(path, "\\.+$", "\")

And see here for more about CF RegExps:

http://www-tcsn.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20654057.html
0
 
LVL 2

Author Comment

by:turbosig
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
0
 
LVL 2

Author Comment

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

Thanks.
0
 
LVL 10

Accepted Solution

by:
D_M_D earned 50 total points
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 15

Expert Comment

by:VincentPuglia
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PERFECT...

Now go get your points...

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

Expert Comment

by:Zontar
Comment Utility
Hey, thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to count occurrences of each item in an array.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now