#18394 - 2002-03-07 01:51 PM
part of string required
|
confusedguy
Lurker
Registered: 2002-03-07
Posts: 4
|
Hi guys,
I am really at a loss here. I am trying to strip a piece of a string entered by a user but I just can't seem to figure out how to do it. Yes, I know how to get the users data and declare variables etc but the problem is this... using the UNC a user enters a server name and files to be copied. Now I am able to strip the server name but after the server name I am not able to get the remainder of line ie \\server1\etc\whatever\james.doc is entered. \\server1 (this is no problem) \etc\whatever\james.doc (this is a headache).
Thanks in advance
_________________________
hmmm grey area :-)
|
|
Top
|
|
|
|
#18395 - 2002-03-07 01:59 PM
Re: part of string required
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you've got the server name part, then just substring the rest based on the length of the server name + 2 for the leading "\\", i.e.
code:
$sRest=substr($sUNCPath,length($sServerName)+2))
|
|
Top
|
|
|
|
#18396 - 2002-03-07 02:18 PM
Re: part of string required
|
Breaker
Hey THIS is FUN
   
Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
|
Richard beat me there! -
Basically this over-complicated snippet should give you an idea of how to break the string down. Also look in the docs at functions like Instr(), Substr(), Len(), Right() and Left().
code:
$string = "\\server1\etc\whatever\james.doc" ;or whatever ? ? "Starting string is: " + $string $x = instr($string,"\\") if $x $string = substr($string,$x+2,len($string)-2) ;chop off first two backslashes endif ? ? "Remove \\ from string: " + $string $x = instr($string,"\") ;find the end of the server name if $x $servername = substr($string,1,$x-1) ;Read from the beginning of the string to the next \ $path = substr($string,$x,len($string)) ;Read from the first \ to the end of the string endif ? ? "Server name from string is: " + $servername $servername = "\\" + $servername ? ? "Replace \\ to prefix server name: " + $servername ? ? "Remainder of path from original string: " + $path :end Exit
HTH
_________________________
================================================ Breaker
|
|
Top
|
|
|
|
#18397 - 2002-03-07 02:21 PM
Re: part of string required
|
confusedguy
Lurker
Registered: 2002-03-07
Posts: 4
|
Thanks Richard! I knew it was something minor that I just wasn't noticing. I have another question now, with your formula is it possible to actually put the variable as the start point from where substr takes it's "start point" (sorry about the redundancy there). Because when I try and use it in the following example:
$sRest=substr($sUNCPath,($location)+1))
$sRest does not obtain any value.
By the way I used +1 because I declared the entire UNC server path as a variable and I needed the rest as a string.
Thanks
_________________________
hmmm grey area :-)
|
|
Top
|
|
|
|
#18398 - 2002-03-07 02:23 PM
Re: part of string required
|
confusedguy
Lurker
Registered: 2002-03-07
Posts: 4
|
Thanks to Breaker as well, I was in the middle of replying to Richard when you posted your reply. Man, you guys must sit waiting patiently all day for people like me to come up with problems :-)
_________________________
hmmm grey area :-)
|
|
Top
|
|
|
|
#18399 - 2002-03-07 04:36 PM
Re: part of string required
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I'm not sure I understand what you are asking for, so here is a fully working scriptlet which will break a UNC path into server and path elements:
code:
$sUNCPath="\\MyServer\path\on\server"
$iIndex=InStr(SubStr($sUNCPath,3),"\") $sServerName=SubStr($sUNCPath,1,$iIndex+1) $sRestOfPath=SubStr($sUNCPath,$iIndex+2)
"Server name is " $sServerName ? "Rest of path is " $sRestOfPath ?
The confusion must be contagious.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 884 anonymous users online.
|
|
|