|
-
June 16th, 2001, 12:22 PM
#1
Split Problems with Inconsistent Text File
I am running a program that shells out to DOS, runs Netstat -an then dumps it to a text file. I want to take this data and put it into a ListView with 5 categories. Most of that I have down. It is parsing the text file that I am having trouble with because the spacing and format is inconsistent:
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP xx.xxx.xxx.xxx:137 0.0.0.0:0 LISTENING
TCP xx.xxx.xxx.119:138 0.0.0.0:0 LISTENING
TCP xx.xxx.xxx.xxx:139 0.0.0.0:0 LISTENING
TCP 127.0.0.1:1025 0.0.0.0:0 LISTENING
TCP 127.0.0.1:2412 0.0.0.0:0 LISTENING
TCP 127.0.0.1:110 0.0.0.0:0 LISTENING
TCP xxx.xxx.xxx
Mainly the problems comes from the amount of characters in any IP address. They are not all the same so I have had a heck of a time using Split function to work poperly. Any ideas or suggestions on another angle of attack for this would be greatly appreciated!
-Dave
-
June 16th, 2001, 07:19 PM
#2
Re: Split Problems with Inconsistent Text File
From the dat you give, I see that it is quite consintent.
You have a string "TCP" Space LocalIP Space ForeignIP "LISTENING", don't you?
So just use the Split function with " " (One space) as the delimeter.
Any number of characters in the IP address doesn't make any difference.
-
June 16th, 2001, 09:42 PM
#3
Re: Split Problems with Inconsistent Text File
Actually, it formatted rather nicely when I posted it here ;-)
In the file there maybe 1 space between TCP and Local IP and then x number of spaces between the next, etc. This is where the inconsistency is. Sorry I wasn't more clear.
Dave
-
June 16th, 2001, 10:35 PM
#4
Re: Split Problems with Inconsistent Text File
Then try this
Strng = "TCP 127.0.0.1:110 0.0.0.0:0 LISTENING"
Do
OldLen = len(Strng)
Strng = Replace(Strng, " ", " ") 'Replace two spaces with one
Loop While OldLen <> len(Strng) 'Until there is no change
MsgBox Strng
It will trim your string so that there is only one space between the fields. Then you can use Split().
-
June 16th, 2001, 10:58 PM
#5
Re: Split Problems with Inconsistent Text File
Ahhh! Looks Good..Much appreciated!
-Dave
-
June 18th, 2001, 04:36 AM
#6
Re: Out of votes!
...And I am already out of votes!!...

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|