Page 1 of 1 1
Topic Options
#148032 - 2005-09-19 11:18 AM Removing characters from a variable
tonyh Offline
Getting the hang of it

Registered: 2002-01-09
Posts: 55
Loc: UK
Hi

I'm trying to write a script to rename workstations names within a script for my company. The computers have many different naming conventions at the mo eg abd123445, cd123456, a123456.
Is there a way within kix that I can look at the computername and and strip out the letters from the start of the computername then I can replace the letters with the new naming standard.

Eg abc123456,zz111111 - remove the abc or zz from the start then I can replace them with a new naming standard.

cheers

Tony
_________________________
Tonyh

Top
#148033 - 2005-09-19 11:34 AM Re: Removing characters from a variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
are you sure you are making new standard or just adding one mess on top of the old ones?
_________________________
!

download KiXnet

Top
#148034 - 2005-09-19 11:49 AM Re: Removing characters from a variable
tonyh Offline
Getting the hang of it

Registered: 2002-01-09
Posts: 55
Loc: UK
We are planning a domain migration from several domains over to active directory - we need to rename all the old worstation to a new naming standard. I need to replace all the letters from start of the workstation name to the new standard.
_________________________
Tonyh

Top
#148035 - 2005-09-19 12:32 PM Re: Removing characters from a variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
try this:
Code:

do
$char=left($computerName,1)
if 57<asc($char)
$computerName=substr($computerName,2)
endif
until 58>asc($char)



that's not the shortest form but you should easily see what I did there.
_________________________
!

download KiXnet

Top
#148036 - 2005-09-19 12:52 PM Re: Removing characters from a variable
tonyh Offline
Getting the hang of it

Registered: 2002-01-09
Posts: 55
Loc: UK
cheers ill give it a go

thanks
_________________________
Tonyh

Top
#148037 - 2005-09-19 01:03 PM Re: Removing characters from a variable
tonyh Offline
Getting the hang of it

Registered: 2002-01-09
Posts: 55
Loc: UK
yeah it works a treat - thanks a million
_________________________
Tonyh

Top
#148038 - 2005-09-19 01:30 PM Re: Removing characters from a variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
obviously, it will fail if the name is consisting only of letters.
this will handle purely numbered names and purely lettered names:
Code:

while 57<asc(left($computerName,1))
$computerName=substr($computerName,2)
loop



and as you see, it's also shorter


Edited by Jooel (2005-09-19 02:54 PM)
_________________________
!

download KiXnet

Top
#148039 - 2005-09-19 01:35 PM Re: Removing characters from a variable
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The Lokenizer © ® strikes again
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148040 - 2005-09-19 02:53 PM Re: Removing characters from a variable
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
missing an asc() in there jooel?
Top
#148041 - 2005-09-19 02:54 PM Re: Removing characters from a variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
fixed and thanks.
_________________________
!

download KiXnet

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 633 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.057 seconds in which 0.023 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