473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Strip unknown range of characters between first "/" and second "/"

Could some help m figure out to strip an unknown range of characters in a
path between the first "/" and "/" found in a folder path somewhere on my
site.

eg: /catamaranco/sales/boat/1.asp
eg: /esserman/newseltter/2004/03/
eg: /yachtservices/excel/reports/

I wish to return only:

"catamaranco"
or
"esserman"
or
"yachtservices"

Thanks for advice...
Jason

Jul 19 '05 #1
16 2800
<%
function stripStuff(str)
stripStuff = str
if instr(str, "/") <> instrRev(str, "/") then
strs = split(str, "/")
stripStuff = strs(1)
end if
end function

response.write "<br>" & stripStuff("/catamaranco/sales/boat/1.asp")
response.write "<br>" & stripStuff("/esserman/newseltter/2004/03/")
response.write "<br>" & stripStuff("/yachtservices/excel/reports/")
%>

--
http://www.aspfaq.com/
(Reverse address to reply.)


<ja***@catamaranco.com> wrote in message
news:#0**************@TK2MSFTNGP09.phx.gbl...
Could some help m figure out to strip an unknown range of characters in a
path between the first "/" and "/" found in a folder path somewhere on my
site.

eg: /catamaranco/sales/boat/1.asp
eg: /esserman/newseltter/2004/03/
eg: /yachtservices/excel/reports/

I wish to return only:

"catamaranco"
or
"esserman"
or
"yachtservices"

Thanks for advice...
Jason

Jul 19 '05 #2
Many thanks - works perfectly!

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
<%
function stripStuff(str)
stripStuff = str
if instr(str, "/") <> instrRev(str, "/") then
strs = split(str, "/")
stripStuff = strs(1)
end if
end function

response.write "<br>" & stripStuff("/catamaranco/sales/boat/1.asp")
response.write "<br>" & stripStuff("/esserman/newseltter/2004/03/")
response.write "<br>" & stripStuff("/yachtservices/excel/reports/")
%>

--
http://www.aspfaq.com/
(Reverse address to reply.)


<ja***@catamaranco.com> wrote in message
news:#0**************@TK2MSFTNGP09.phx.gbl...
Could some help m figure out to strip an unknown range of characters in a path between the first "/" and "/" found in a folder path somewhere on my site.

eg: /catamaranco/sales/boat/1.asp
eg: /esserman/newseltter/2004/03/
eg: /yachtservices/excel/reports/

I wish to return only:

"catamaranco"
or
"esserman"
or
"yachtservices"

Thanks for advice...
Jason


Jul 19 '05 #3
Umm :) sorry Aaron, I ran into an added problem after extracting the
string...how I would then also pull out the remaiing 'stuff' and stuff that
into a variable?.

Extract: "/sales/boat/1.asp"

x= "/catamaranco/sales/boat/1.asp"

As my ultimate goal is concententation:

"www". & stripStuff("/catamaranco/sales/boat/1.asp") & ".com" & "/" &
stripTrailingStuff(X)

Result: www.catamaranco.com/sales/boat/1.asp"
<ja***@catamaranco.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Many thanks - works perfectly!

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
<%
function stripStuff(str)
stripStuff = str
if instr(str, "/") <> instrRev(str, "/") then
strs = split(str, "/")
stripStuff = strs(1)
end if
end function

response.write "<br>" & stripStuff("/catamaranco/sales/boat/1.asp")
response.write "<br>" & stripStuff("/esserman/newseltter/2004/03/")
response.write "<br>" & stripStuff("/yachtservices/excel/reports/")
%>

--
http://www.aspfaq.com/
(Reverse address to reply.)


<ja***@catamaranco.com> wrote in message
news:#0**************@TK2MSFTNGP09.phx.gbl...
Could some help m figure out to strip an unknown range of characters
in
a path between the first "/" and "/" found in a folder path somewhere on my site.

eg: /catamaranco/sales/boat/1.asp
eg: /esserman/newseltter/2004/03/
eg: /yachtservices/excel/reports/

I wish to return only:

"catamaranco"
or
"esserman"
or
"yachtservices"

Thanks for advice...
Jason



Jul 19 '05 #4
Ok, I did come up with my own solution...but it seems to waste far too many
lines of code...could you tell me if there is a better way to write this:

u_CurrentURL="/catamaranco/sales/boat/1.asp"

function stripParentDirectory(str)
stripParentDirectory = str
if instr(str, "/") <> instrRev(str, "/") then

strs = split(str, "/")
stripParentDirectory = strs(1)

end if
end function

ParentDir= stripParentDirectory(u_CurrentURL)

Call SubDirPath(ParentDir, u_CurrentURL)
Sub SubDirPath(ParentDir, u_CurrentURL)

strLen = len(u_CurrentURL)
response.write "<br><br>Total String Length:" & strLen &
"<br><br>"
ParDirLen=len(ParentDir) + 2 '//add slash x 2
response.write "<br><br>Parent Dir Length:" & ParDirLen &
"<br><br>"
SubPathLen= strLen - ParDirLen
response.write "<br><br>SubPath Length:" & SubPathLen &
"<br><br>"
Response.write SubPathLen

MyString= Right(u_CurrentURL,SubPathLen)
response.write "<BR><BR>http://www." & ParentDir & ".com/" &
MyString

End Sub

Result: http://www.catamaranco.com/sales/boat/1.asp
Jul 19 '05 #5
I readpated the script with an extra function which seems to work....is this
more elegant
<%
u_CurrentURL="/catamaranco/sales/boat/1.asp"
function stripParentDirectory(str)
stripParentDirectory = str
if instr(str, "/") <> instrRev(str, "/") then
strs = split(str, "/")
stripParentDirectory = strs(1)
end if
end function
Function stripSubPath(ParentDir, u_CurrentURL)

strLen = len(u_CurrentURL)
'//response.write "<br><br>Total String Length:" & strLen &
"<br><br>"
ParDirLen=len(ParentDir) + 2 '//add slash x 2
'//response.write "<br><br>Parent Dir Length:" & ParDirLen &
"<br><br>"

SubPathLen= strLen - ParDirLen
'//response.write "<br><br>SubPath Length:" & SubPathLen & "<br><br>"
'//Response.write SubPathLen

MyString= Right(u_CurrentURL,SubPathLen)
MyString ="http://www." & ParentDir & ".com/" & MyString

stripSubPath =MyString

End Function
ParentDir= stripParentDirectory(u_CurrentURL)
Response.write stripSubPath(ParentDir, u_CurrentURL)

%>
Jul 19 '05 #6
<ja***@catamaranco.com> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
Umm :) sorry Aaron, I ran into an added problem after extracting the
string...how I would then also pull out the remaiing 'stuff' and stuff that into a variable?.

Extract: "/sales/boat/1.asp"

x= "/catamaranco/sales/boat/1.asp"

As my ultimate goal is concententation:

"www". & stripStuff("/catamaranco/sales/boat/1.asp") & ".com" & "/" &
stripTrailingStuff(X)

Result: www.catamaranco.com/sales/boat/1.asp"


<script language="JavaScript" runat="SERVER">
var s = "/catamaranco/sales/boat/1.asp";
Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
</script>
<br>
<script language="VBScript" runat="SERVER">
Dim re : Set re = New RegExp
With re
.Pattern = "^/([^/]*)"
.Global = True
Response.Write .Replace(s,"www.$1.com")
End With
</script>
Jul 19 '05 #7
Chris Hohmann wrote on 21 aug 2004 in
microsoft.public.inetserver.asp.general:
<script language="JavaScript" runat="SERVER">
var s = "/catamaranco/sales/boat/1.asp";
Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
</script>
Response.write(
[case]
<br>
<script language="VBScript" runat="SERVER">
Dim re : Set re = New RegExp
With re
.Pattern = "^/([^/]*)"
.Global = True
[Global is not effective with ^ as start of string,
anyway global=true is not what you want here.]
Response.Write .Replace(s,"www.$1.com")
End With
</script>


[If the default <%%> language is jscript the order will be reversed,
so s will not be defined yet for the vbscript part, IMHO & not tested;-)]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #8

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Chris Hohmann wrote on 21 aug 2004 in
microsoft.public.inetserver.asp.general:
<script language="JavaScript" runat="SERVER">
var s = "/catamaranco/sales/boat/1.asp";
Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
</script>


Response.write(
[case]


I'm not sure what this means.

<br>
<script language="VBScript" runat="SERVER">
Dim re : Set re = New RegExp
With re
.Pattern = "^/([^/]*)"
.Global = True


[Global is not effective with ^ as start of string,
anyway global=true is not what you want here.]

You're correct. My intention was to set Global to false. That's what I get
for sutting and pasting. However, there are cases when searching on "^"
while having global set to true is useful, ie. when multiline is turned on.
Response.Write .Replace(s,"www.$1.com")
End With
</script>


[If the default <%%> language is jscript the order will be reversed,
so s will not be defined yet for the vbscript part, IMHO & not tested;-)]


Yes, although in this particular circumstance it was more of a "one or the
other" scenario, not both.
Jul 19 '05 #9
Chris Hohmann wrote on 23 aug 2004 in
microsoft.public.inetserver.asp.general:
> <script language="JavaScript" runat="SERVER">
> var s = "/catamaranco/sales/boat/1.asp";
> Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
> </script>


Response.write(
[case]


I'm not sure what this means.


See the difference!

..write should be lower case in javascript

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #10
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Chris Hohmann wrote on 23 aug 2004 in
microsoft.public.inetserver.asp.general:
> <script language="JavaScript" runat="SERVER">
> var s = "/catamaranco/sales/boat/1.asp";
> Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
> </script>

Response.write(
[case]


I'm not sure what this means.


See the difference!

.write should be lower case in javascript


Response is a built-in ASP object. As such the names of its
methods/members/properties are independent of the scripting language. Here's
the documentation on the Response.Write method, listing it with a capital
"W":

http://www.msdn.microsoft.com/librar...resomwrite.asp
Jul 19 '05 #11
Chris Hohmann wrote on 23 aug 2004 in
microsoft.public.inetserver.asp.general:
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Chris Hohmann wrote on 23 aug 2004 in
microsoft.public.inetserver.asp.general:
>> > <script language="JavaScript" runat="SERVER">
>> > var s = "/catamaranco/sales/boat/1.asp";
>> > Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
>> > </script>
>>
>> Response.write(
>> [case]
>
> I'm not sure what this means.
See the difference!

.write should be lower case in javascript


Response is a built-in ASP object. As such the names of its
methods/members/properties are independent of the scripting language.


I didn't know that, Chris, silly me. ;-)
Here's the documentation on the Response.Write method, listing it with
a capital "W":
http://www.msdn.microsoft.com/librar...f_vbom_resomwr
ite.asp


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #12
Evertjan. wrote:

Response.write(
[case]


I'm not sure what this means.


See the difference!

.write should be lower case in javascript


I don't know about javascript, but if this suddenly became true in JScript,
I would have a lot of work to do....
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #13
Dave Anderson wrote on 23 aug 2004 in
microsoft.public.inetserver.asp.general:
.write should be lower case in javascript


I don't know about javascript, but if this suddenly became true in
JScript, I would have a lot of work to do....


as I was told, Response.Write is not a part of the language, but of a
server object that is caseinsensitive, so

ResPOnse.wrITE('Hi') should be valid.

=============

However jscript in IE is not so forgiving with document.write:

<script type="text/jscript">
document.Write('Hi')
</script>

gives an error!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #14
"Evertjan." wrote:

as I was told, Response.Write is not a part of the language,
but of a server object that is caseinsensitive, so

ResPOnse.wrITE('Hi') should be valid.


No, that's not what you were told. The Response object does not require case
sensitivity for accessing its properties and methods, but the Response
object still must be found in the global namespace, and accordingly must be
spelled exactly "Response":

Microsoft JScript runtime error '800a1391'
'ResPOnse' is undefined
If you had spent 5 seconds testing either of your assertions, you may have
seen that for yourself.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #15
Dave Anderson wrote on 24 aug 2004 in
microsoft.public.inetserver.asp.general:
"Evertjan." wrote:

as I was told, Response.Write is not a part of the language,
but of a server object that is caseinsensitive, so

ResPOnse.wrITE('Hi') should be valid.


No, that's not what you were told. The Response object does not
require case sensitivity for accessing its properties and methods, but
the Response object still must be found in the global namespace, and
accordingly must be spelled exactly "Response":

Microsoft JScript runtime error '800a1391'
'ResPOnse' is undefined
If you had spent 5 seconds testing either of your assertions, you may
have seen that for yourself.


So now I am. Told that is.

You were wrong about the 5 seconds, though.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #16
Evertjan. wrote:
If you had spent 5 seconds testing either of your assertions,
you may have seen that for yourself.


So now I am. Told that is.

You were wrong about the 5 seconds, though.


Fair enough. I suppose the day was getting long and my nerves short. Sorry.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Giampiero Gabbiani | last post by:
Hi to all, Is there a simple way to implement a strip algorithm on std::string using STL? I'm sure that it's possible to implement it using some transform, but my knowledge of STL is POOR. ...
3
by: Marcus | last post by:
I'm running into a situation that has me adding a value of "Unknown" to a reference table. I am being pulled between two trains of thought, and was curious to get other's input on in. I give an...
8
by: Frank Ratzlow | last post by:
Hi folks, I have a list of entries where some entries contain the special character (quotes) within in the string. If I try to save this entry everything after the quotes is skipped. The reason...
3
by: alex.mcshane | last post by:
Hi - I would be grateful for any advice on the following. Within DB2 for OS/390, the STRIP Scaler Function is available. Its function is, for example, to remove leading zeros from a string. ...
6
by: rtilley | last post by:
s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious......
1
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
4
by: Steve | last post by:
Hi, I'm a complete PHP n00b slowly finding my way around I'm using the following function that I found on php.net to strip out html and return only the text. It works well except for when you...
3
by: Colin J. Williams | last post by:
The Library Reference has strip( ) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed....
4
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.