/bundles/itninjaweb/img/Breadcrumb_cap_w.png
Hi,

I have c:\test\iplist.txt.

This contains lists of IP Addresses (I've put XXX instead of the numbers):

(IP)-10.XXX.XX.XXX

(IP)-10.XXX.XX.XX

(IP)-10.XXX.XX.XXX

(IP)-10.XXX.XX.XXX

(IP)-10.XXX.XX.XXX

(IP)-10.XXX.XX.XXX

(IP)-10.XXX.XX.XXX

What's the best way to go through the list and trim the first 5 characters from each line?

Thanks.
0 Comments   [ - ] Hide Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity

Answers

0
- Use the FileSystemObject to open the file
- Use the .ReadAll method to read the file's contents into a string
- Use Split to convert the string into an array, using VBS's built-in vbNewLine constant as the separator for Split
- Do a normal 'For x = LBound(arrTextFile) To UBound(arrTextFile)' to get each element's value
- Use Split again to build the string you require, this time using '.' as the separator. I suggest that rather than Left, Right or Mid because you'll presumably be getting addresses like '1.1.1.1' as well as '255.255.255.255' i.e. you can't easily tell what 5 characters you want unless you add reams of code to check the length of each address segment.
Answered 12/19/2007 by: VBScab
Red Belt

Please log in to comment
0
This will msgbox each entry with the first 5 characters removed.

' vbCrLf is also a vbs constant - that handles the 'Returns' at the end of each line.

'Setup File system object - of course - my referene to this is oFSO
Dim fileData : fileData = oFSO.ReadAll
Dim arrIPData : arrIPData = Split(fileData, vbCrLf)
Dim strIP '<------------- EDIT ------ OOps forgot to dim this
For Each strIP in arrIPData
Dim StripedIP : StripedIP = ""
If len(strIP) > 5 Then StripedIP = Right(strIP,(len(Trim(strIP)) - 5))
msgbox(StripedIP)
Next

-------------------
If you need to deal with an unknown ip such as 1.1.1.1 to 255.255.255.255 as VBScab mentions then do this..
For Each strIP in arrIPData
Dim arrIP : arrIP = Split(strIP, ".")

'The desired strip from a full IP -- xxx.xxx.xxx.xxx
Dim intCharToStrip : intCharToStrip = 6
'Determine if first octet is less than 3 numbers and subtract from number to strip
'since you have an ip of 10.xxx.xxx.xxx - this will set your number to 5
intCharToStrip = intCharToStrip - (3 - len(arrIP(0)))
'Same concept, but will detect if the second octet is not full...
intCharToStrip = intCharToStrip - (3 - len(arrIP(1)))

Dim StripedIP : StripedIP = ""
If len(strIP) > intCharToStrip Then StripedIP = Right(strIP,(len(Trim(strIP)) - intCharToStrip ))
msgbox(StripedIP)
Next
Answered 12/19/2007 by: gmorgan618
Blue Belt

Please log in to comment
0
Thanks to you both for your excellent replies. Sorry I hadn't acknolwledge you replies any sooner - I must have had to move onto other tasks at the time.
Answered 07/17/2008 by: Meic
Second Degree Blue Belt

Please log in to comment