Page 1 of 1 1
Topic Options
#117851 - 2004-04-14 10:59 AM Last part of variable
lawe009 Offline
Fresh Scripter

Registered: 2004-04-14
Posts: 36
Hi,
I´m new to this board and got a newbie question. How do I get the last part of a variable? I´m running Metaframe with local and network printers and I want to know the default printer. I got a script, from here, which checks this but it can look like "Client\computername#\\\server\HP LaserJet 4100 PCL 6" to "HP Laserjet 4100 PCL 6". I´m just interested in the last part the name, the printername. How do I do this? The script I´m using is:
Code:
$PrinterKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
$PrinterVal = "Device"
$TempString = READVALUE ($PrinterKey, $PrinterVal)

;The Printername is the first part of the registry value
$x = INSTR($TempString,",")
$DefPrint = SUBSTR($TempString,1,$x-1)

$DefPrint

Regards Lars

Top
#117852 - 2004-04-14 11:50 AM Re: Last part of variable
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Welcome to the board,

if you use a later Kixtart version (since 4.x) you can do that by a split:

Code:

break on

$string = "Client\computername#\\\server\HP LaserJet 4100 PCL 6"

$Printername = split($string, "\")[ubound(split($string, "\"))]

"Printername = " + $Printername

get $

exit 1




hth
_________________________



Top
#117853 - 2004-04-14 12:05 PM Re: Last part of variable
lawe009 Offline
Fresh Scripter

Registered: 2004-04-14
Posts: 36
Thanx Jochen,
Works fine.
Regards Lars

Top
#117854 - 2004-04-14 12:05 PM Re: Last part of variable
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hm, maybe this needs a bit explanation:

Code:
$Printername = split($string, "\")[ubound(split($string, "\"))]



One can reference to an element of the created array in the same step as split creates it. In this case the last element (ubound()).

Simplified:

$var = split( string , delimiter ) [ element ]
_________________________



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 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.048 seconds in which 0.02 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