Jump to content
Sign in to follow this  
allSystemsGo

StringReplace woes

Recommended Posts

allSystemsGo

So I am working on a small project that at the moment grabs a list of PCs that are connected to the network and displays their IP address. The functionality is there but I am having one small issue. I have two StringReplace functions going on. The first one fails, but the other works. I have this same snippet of code in another script of mine that works just fine. The only difference is the name of the variables. Care to take a look and help me see what I am not seeing?

#include <Filev1.au3>
#include <array.au3>

DirCreate("c:\temp")
netreport()

Func netreport()
    Dim $report[50][3]
    $report[0][0] = "Computer name"
    $report [0][1] = "IP Address"


    $pcnames = "c:\temp\pcnames.txt"
    RunWait(@Comspec & " /c " & "net view > " & $pcnames, "" , @SW_HIDE)
    FileOpen($pcnames,0)
    $x= 1
    For $i= 4 to 100
        $name = FileReadLine($pcnames,$i)
        $name = StringTrimLeft($name,2)
        $ip = RunWait(@Comspec & " /c " & "ping " & $name & ' -n 1 |Find "[" > c:\temp\yip.txt', "", @SW_HIDE)
        $iptxt = FileOpen("c:\temp\yip.txt",0)
        $ip = FileRead($iptxt)
;~      MsgBox(64,"text",$ip)
        $ip=StringReplace($ip,"Pinging "& $name &" [", " ") ; this does not work
        $ip=StringReplace($ip,"] with 32 bytes of data:"," ") ; this does work
;~      MsgBox(64,"test",$ip)
        $report[$x][0] = $name
        $report[$x][1] = $ip
        $i = $i + 1
        $x = $x + 1
    Next
    _ArrayDisplay($report)

    EndFunc
Edited by allSystemsGo

Share this post


Link to post
Share on other sites
Melba23

allSystemsGo,

I would imagine that the function does not find the exact string you wish to replace and so fails. Are you sure that the string is correct? Have you checked in a binary editor that it matches? :huh:

Perhaps post an example file here so we can look at it. And you might be better going with StringRegExpReplace in any case. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
mikell

Something like this maybe ? ;)

$ip = "Pinging tralala [192.168.1.1] with 32 bytes of data:"
$ip = StringRegExpReplace($ip,'.+\[([^]]+).+', " $1 ") 
msgbox(0,"", $ip)

Share this post


Link to post
Share on other sites
allSystemsGo

@Mikell

That did the trick. Thanks for your help.

Share this post


Link to post
Share on other sites
mikell

Melba pointed to the scent, I only wrote the conclusion :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×