Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript split array question

Status
Not open for further replies.

jarves123

Systems Engineer
Apr 10, 2019
3
0
0
PH
Hi,

I have a vbscript that runs the command "netsh dhcp server scope show clients 1" and captures and reads its output line by line and Split each line and stores it into array elements. The only separate that seems plausible to use is the dash "-".
The output of netsh dhcp server scope show client 1 is this:

10.228.64.11 - 255.255.255.0 - 54-e1-ad-f6-a8-1d -4/16/2019 9:49:27 AM -D- 1077419.abc.com

i can use the split function like the one below but the problem is that the 3rd column has lots of "-" which is part of one element. So using "-" as separate will not be a good idea.
splitLine = Split(scopeArray(scopeItem),"-")

How should I approach this?
 
What about using " - " instead (and continue processing of third item if necessary)? Split is not limited to single character delimiter.

combo
 
I tried it already but there are entries like the one below having several spaces before the "-" then there is one with no space before and after "-"

10.228.164.0 - 255.255.255.128-Active -Sample test-CNC000000123
 
What output you expect? Trim, InStr, InstrRev can be used to process the string, but string structure rules have to be clear.

combo
 
I tried it already but there are entries like the one below having several spaces before the "-" then there is one with no space before and after "-"

You'll need to search and replace in order to end up with " - "

For instance search for " -" replace with " -". Run until no replacements.

Then do it on the right side of the dash.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
When I run the command to show dhcp server scopes this is the output.

vbscriptarrayqurstion_d4hvdb.png


since the scope name is separated by "-" in the sample image "Total-LAN" becomes two elements and "Total-Corp-Wifi" becomes 3 array elements. There are other entries also that has more than 3 dashes(just not show here).

using vbscript i want to display them as one array element.

i want to output the scope name such that they are one element with the "-" in its name.

wscript.echo splitarrar(3) has no problem displaying the Scope Name that has no dashes

My problem is displaying the ones with dashes.
 
You won't complete this task with one-liner formula. Also, splitting input with single character divisor will fail, as "-" can be inside an item you want keep together.
So at first find a logic for splitting input string into elements you need to keep separate. Splitters seem to be dashes with space. You can preprocess the string replacing " -" and "- " by unique delimiter (pipeline?) or other characters. Next split the string. Next complete processing the parts - as removing extra spaces etc.

combo
 
I would try solving this with a RegEx.
You know you can expect an IP pattern for scope and subnet, some word pattern for state and scope. Also, your initial string contains a datetime.
I managed to identify the parts of your initial string with this regex (making some groups optional to allow NULL entries):
Code:
([\d\.]+)?(\s+?)(\-\s+?)([\d\.]+)?(\s+?)(\-\s+?)([a-f0-9\-]{17})?(\s+?)(\-\s?)([\d\/]+?\s[\d\:]+?\s[APM]+?)?(\s?\-)([\w]+?)(\s?\-\s?)(.+)?
The single parts are then:
[ul]
[li]match group 1: IP[/li]
[li]match group 4: subnet[/li]
[li]group 7: MAC address (?)[/li]
[li]group 10: datetime[/li]
[li]group 12: "D"[/li]
[li]group 14: URL[/li]
[/ul]

Would that be an option?

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Bit confused - your original post suggest you are dealing with:

[tt]10.228.64.11 - 255.255.255.0 - 54-e1-ad-f6-a8-1d -4/16/2019 9:49:27 AM -D- 1077419.abc.com[/tt]

But your later image suggests

[tt]10.128.161.128 - 255.255.255.128 -Active -CDCO Lime WiFi -iPAds[/tt]

Which is it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top