have the following:

strPath = "\\server\folder\folder"
strPath = Mid(strPath, 3)
strPath = Mid(strPath, 1, InStr(strPath, "\") - 1)
Wscript.Echo strPath

obviously what im doing is plucking out only the server name from the unc
path.
is there no way i could do this with one statement instead of 2?

Re: string functions KILLING me, help! :o) by Bob

Bob
Mon Jun 18 12:45:07 CDT 2007

S Moran wrote:
> have the following:
>
> strPath = "\\server\folder\folder"
> strPath = Mid(strPath, 3)
> strPath = Mid(strPath, 1, InStr(strPath, "\") - 1)
> Wscript.Echo strPath
>
> obviously what im doing is plucking out only the server name from the
> unc path.
> is there no way i could do this with one statement instead of 2?

What you have there works, does it not? What's the problem? It's not
like you're going to get a huge performance boost by whittling this down
to a single line.

However, Instr takes up to 4 arguments. Try this:

strPath = "\\server\folder\folder"
strpath = split(strpath,"\")(2)

There's probably a regular expression that could do this as well ...

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: string functions KILLING me, help! :o) by ekkehard

ekkehard
Mon Jun 18 12:53:24 CDT 2007

S Moran schrieb:
> have the following:
>
> strPath = "\\server\folder\folder"
> strPath = Mid(strPath, 3)
> strPath = Mid(strPath, 1, InStr(strPath, "\") - 1)
> Wscript.Echo strPath
>
> obviously what im doing is plucking out only the server name from the
> unc path.
> is there no way i could do this with one statement instead of 2?
>
WScript.Echo ">" + Split( "\\server\folder\folder", "\" )( 2 ) + "<"

Re: string functions KILLING me, help! :o) by S

S
Mon Jun 18 13:25:57 CDT 2007

thanks... you said instr takes up to 4 args, then you didnt use instr in
your example. did i miss something?


"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:eA9cqBdsHHA.1216@TK2MSFTNGP04.phx.gbl...
>S Moran wrote:
>> have the following:
>>
>> strPath = "\\server\folder\folder"
>> strPath = Mid(strPath, 3)
>> strPath = Mid(strPath, 1, InStr(strPath, "\") - 1)
>> Wscript.Echo strPath
>>
>> obviously what im doing is plucking out only the server name from the
>> unc path.
>> is there no way i could do this with one statement instead of 2?
>
> What you have there works, does it not? What's the problem? It's not
> like you're going to get a huge performance boost by whittling this down
> to a single line.
>
> However, Instr takes up to 4 arguments. Try this:
>
> strPath = "\\server\folder\folder"
> strpath = split(strpath,"\")(2)
>
> There's probably a regular expression that could do this as well ...
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>


Re: string functions KILLING me, help! :o) by Bob

Bob
Mon Jun 18 13:45:40 CDT 2007

Nope. I changed my mind at the last second and used Split instead.
Slightly less complicated than using InStr. Off the top of my head, it
would look like this:

strpath=Mid(strpath,3, Instr(3,strpath,"\") - 3)

You can look up the purpose of the 4th argument in online help:
http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en

S Moran wrote:
> thanks... you said instr takes up to 4 args, then you didnt use instr
> in your example. did i miss something?
>
>
> "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
> news:eA9cqBdsHHA.1216@TK2MSFTNGP04.phx.gbl...
>> S Moran wrote:
>>> have the following:
>>>
>>> strPath = "\\server\folder\folder"
>>> strPath = Mid(strPath, 3)
>>> strPath = Mid(strPath, 1, InStr(strPath, "\") - 1)
>>> Wscript.Echo strPath
>>>
>>> obviously what im doing is plucking out only the server name from
>>> the unc path.
>>> is there no way i could do this with one statement instead of 2?
>>
>> What you have there works, does it not? What's the problem? It's not
>> like you're going to get a huge performance boost by whittling this
>> down to a single line.
>>
>> However, Instr takes up to 4 arguments. Try this:
>>
>> strPath = "\\server\folder\folder"
>> strpath = split(strpath,"\")(2)
>>
>> There's probably a regular expression that could do this as well ...
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: string functions KILLING me, help! :o) by ekkehard

ekkehard
Mon Jun 18 14:06:30 CDT 2007

S Moran schrieb:
> have the following:
>
> strPath = "\\server\folder\folder"
> strPath = Mid(strPath, 3)
> strPath = Mid(strPath, 1, InStr(strPath, "\") - 1)
> Wscript.Echo strPath
>
> obviously what im doing is plucking out only the server name from the
> unc path.
> is there no way i could do this with one statement instead of 2?
>
Collection of 3 possible solutions:

Dim sSrc : sSrc = "\\server\folder\folder"
Dim oRE : Set oRE = New RegExp
oRE.Pattern = "^\\\\([^\\]+)\\"
WScript.Echo ">" + Split( sSrc, "\" )( 2 ) + "<"
WScript.Echo ">" + Mid( sSrc, 3, Instr( 3, sSrc, "\" ) - 3) + "<"
WScript.Echo ">" + oRE.Execute( sSrc )( 0 ).SubMatches( 0 ) + "<"

Re: string functions KILLING me, help! :o) by Anthony

Anthony
Tue Jun 19 02:56:02 CDT 2007


"S Moran" <s@moran.com> wrote in message
news:uV28w5csHHA.484@TK2MSFTNGP06.phx.gbl...
> have the following:
>
> strPath = "\\server\folder\folder"
> strPath = Mid(strPath, 3)
> strPath = Mid(strPath, 1, InStr(strPath, "\") - 1)
> Wscript.Echo strPath
>
> obviously what im doing is plucking out only the server name from the unc
> path.
> is there no way i could do this with one statement instead of 2?
>

Here's my solution:-

Function GetServer(Path)
GetServer = Mid(Path, 3, InStr(3, Path, "\")-3)
End Function

Wscript.Echo GetServer("\\server\folder\folder")

It has the advantage over the solutions using split in that it only creates
the desired new string not an array of strings from which another is copied.

However the primary point is that most often the desire for a single line
isn't for performance but for readablility of code. Well named functions
to perform simple operations such as this are an often overlooked way to
achieve readability. It's also re-usable.