Page 1 of 1 1
Topic Options
#204300 - 2012-02-15 06:01 PM Help with Substr Command
ItsComplicated Offline
Just in Town

Registered: 2012-02-09
Posts: 2
Loc: CA
I'm trying to figure out what the below script does. For some reason its not returning the results I expected. Can someone please explain it to me?

substr(@wksta, len(@wksta) -2, 3)

Top
#204301 - 2012-02-15 06:09 PM Re: Help with Substr Command [Re: ItsComplicated]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
if @wksta = "Computer"

len("Computer")=8
8-2=6

substr("Computer",6,3)="ter"

which is the same thing as right("Computer",3)
_________________________
(... better days ahead)

Top
#204302 - 2012-02-15 06:10 PM Re: Help with Substr Command [Re: ItsComplicated]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Welcome to KORG!

The SubStr command will extract a section of text from a string. In this case, the string is the Workstation Name (@WKSTA). The second parameter is the starting location - length of the computer name minus 2. The third parameter is the number of characters to return.

So - if the name is "MyWorkstation", the length is 13, the start is then 11, and 3 chars starting at position 11 are returned - "ion" in this case.

This is an extremely difficult and round-about method to get the last 3 characters of the hostname, which can be shorted (and simplified) to
 Code:
Right(@WKSTA, 3)
Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#204303 - 2012-02-15 06:14 PM Re: Help with Substr Command [Re: Glenn Barnas]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
Ha... got you by 22secs \:\) Good for him though... as we explained it in words and examples.
_________________________
(... better days ahead)

Top
#204304 - 2012-02-15 07:11 PM Re: Help with Substr Command [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Yeah - I wrote more - takes longer as you get older... \:D
_________________________
Actually I am a Rocket Scientist! \:D

Top
#204307 - 2012-02-15 07:29 PM Re: Help with Substr Command [Re: Glenn Barnas]
ItsComplicated Offline
Just in Town

Registered: 2012-02-09
Posts: 2
Loc: CA
Thanks everyone for your responses. I was on the right track, just not really understanding how the -2 came into play. Great explanations! I really appreciate it!!!
Top
Page 1 of 1 1


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

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.069 seconds in which 0.046 seconds were spent on a total of 13 queries. Zlib compression enabled.

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