Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

vbscript split array question

vbscript split array question

vbscript split array question


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: - - 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?

RE: vbscript split array question

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


RE: vbscript split array question

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 "-" - -Sample test-CNC000000123

RE: vbscript split array question

What output you expect? Trim, InStr, InstrRev can be used to process the string, but string structure rules have to be clear.


RE: vbscript split array question


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.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: vbscript split array question

When I run the command to show dhcp server scopes this is the output.

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.

RE: vbscript split array question

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.


RE: vbscript split array question

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):


The single parts are then:
  • match group 1: IP
  • match group 4: subnet
  • group 7: MAC address (?)
  • group 10: datetime
  • group 12: "D"
  • group 14: URL
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.

RE: vbscript split array question

Bit confused - your original post suggest you are dealing with: - - 54-e1-ad-f6-a8-1d -4/16/2019 9:49:27 AM -D- 1077419.abc.com

But your later image suggests - -Active -CDCO Lime WiFi -iPAds

Which is it?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close