1984
(Starting to like KiXtart)
2003-11-27 01:27 PM
How to split a string and captures part of that?

Hi,

Im trying to use Instr and Split command to capture the retured value of "Name" in the bellow "nbtstat -c" output.
I cannot make it work Anybody knows how to do???

Name Type Host Address Life [sec]
------------------------------------------------------------
CyrusA <20> UNIQUE 192.168.0.33 502

LOTR1 <03> UNIQUE 192.168.0.33 600

Simply i need $UserID = CyrusA and $Computer = LOTR1

note there is blank space between each string.

BR
/C


Radimus
(KiX Supporter)
2003-11-27 02:00 PM
Re: How to split a string and captures part of that?

Code:
 break on

$cmd='cmd /c nbtstat -c|find "<"'
$return=wshpipe($cmd,1)
for each $line in $return
if trim($line) > ' '
? $line
$computer = trim(split($line,'<')[0])
$ip = trim(left(trim(split($line,'UNIQUE')[1]),16))
? $computer
? $ip
?
endif
next

;********************************************************************************************
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
While Not $oExec.Status Loop
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If Not $NoEcho $Output Endif
$WshPipe=Split($Output,CHR(10))
Exit($oExec.ExitCode)
EndFunction



Howard Bullock
(KiX Supporter)
2003-11-27 02:03 PM
Re: How to split a string and captures part of that?

There can be more than one entry in these results, but the easiest way to get the first part of the line is:

Code:
$name = split($line, chr(32))[0]  



1984
(Starting to like KiXtart)
2003-11-27 02:08 PM
Re: How to split a string and captures part of that?

The Computer name in secound row "LOTR1" - Can I get that value in the same script?

Thanx


Howard Bullock
(KiX Supporter)
2003-11-27 02:23 PM
Re: How to split a string and captures part of that?

Rad's previous post would handle multiple lines.