Page 1 of 1 1
Topic Options
#100166 - 2003-04-03 06:23 PM Help Needed on Length problem
Rob Schraeger Offline
Lurker

Registered: 2003-04-03
Posts: 1
I have a script that I need to trim the last 7 characters off from a result of a variable.

Example

$X would display \\servername\sharename.

I want to trim everything except the servername. The server name can be any length from 6-10 letters.

I looked a SUBSTR and LTRIM and RTRIM but can get even close.

Help is needed and appreciated.

Top
#100167 - 2003-04-03 06:29 PM Re: Help Needed on Length problem
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
use:
$path = split('\\server\share\folder\file.ext','\')
$server=$path[2]
$share=$path[3]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#100168 - 2003-04-03 06:29 PM Re: Help Needed on Length problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Then look at INSTR/INSTRREV or SPLIT.
code:
$x='\\servername\sharename'
$server=split(substr($x,3)$x,'\')[0]

_________________________
There are two types of vessels, submarines and targets.

Top
#100169 - 2003-04-03 06:30 PM Re: Help Needed on Length problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
How about:

$STRING = "\\servername\sharename"

? SUBSTR(SUBSTR($STRING,1,INSTRREV($STRING,"\")-1),3)

But you will probably get some other takes on this. Requires the INSTRREV function which was recently added (few releases ago).

-Shawn

Top
#100170 - 2003-04-03 06:32 PM Re: Help Needed on Length problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Did I say something about "more takes on this" ? Actually imho I like the SPLIT take better.
Top
#100171 - 2003-04-03 06:33 PM Re: Help Needed on Length problem
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
Rob,

I get Hotmail messages with titles like that! [Wink]

How about trying something like this:

code:
$x = "\\servername\sharename"
$x = Left($x,Len($x)-7)
? $x

Assuming that you will always be trimming exactly 7 characters of the end of the string.

If what you actually want to do is return the servername from a string like the above, then I suggest using the Split() function to create an array of the discrete chunks of the string separated by "\", then reconstituting the "\\servername" part by choosing that element of the array.

I would suggest you read the fine manual, and search the FAQ forum on this board to get more idea of how to do this.

-Breaker
_________________________
================================================
Breaker


Top
#100172 - 2003-04-03 06:35 PM Re: Help Needed on Length problem
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
[Big Grin] [Big Grin] [Big Grin]

I get those emails too
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#100173 - 2003-04-03 06:41 PM Re: Help Needed on Length problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Kixtart ... It's how you use it that counts.
Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.058 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org