Sign in to follow this  
Followers 0
gcue

stringsplit + stringleft

8 posts in this topic

im trying to determine the first two quartets for my ip (and seperate each quartet into two vars)

i was doing this (which works for ips with two digits in each quartet):

$myIP = StringLeft(_GetIP(), 5)

$myaIP = StringLeft($myIP, 2)

$mybIP = StringRight($myIP, 2)

but this wont account for sets that have 3 digits =/

AAA.BBB.CCC.DDD

i figure id need something with stringsplit which would use the "." as a delimiter.. but theres multiple "."!!!

any ideas?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You want the first two quartets? Just StringSplit on '.' and read indexes 1 and 2. That's much easier if you ask me.

$firsttwoarray = StringSplit("192.168.2.88", ".")

$firsttwo = $firsttwoarray[1] & "." & $firsttwoarray[2]

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)

not so good :) you can give more than 3 digits per quarter

\A([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\z

is better ( The String must only consist out of the IP, too :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

i just did

$mIP = StringSplit(_GetIP(), ".")

$myIP = $mIP[1] & "." & $mIP[2]

forsee any issues?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yes, _GetIP() gets the ip from an external website so if the computer is offline there will be no array so $mIP[1] will cause a crash.

Rather do:

$mIP = StringSplit(_GetIP(), ".")
If Not @error Then
$myIP = $mIP[1] & "." & $mIP[2]
Else
$myIP="127.0"
EndIf

:)

Edit: Fixed code

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)

not so good :) you can give more than 3 digits per quarter

\A([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\z

is better ( The String must only consist out of the IP, too :)

Well given that _GetIP() returns a valid IP or -1, I didn't think I needed to be too strict with greediness.

Share this post


Link to post
Share on other sites

Whoever said that there can be more than 3 digits in a quartet is an idiot. The range per quartet is 0-255 inclusive.

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  
Followers 0