Jump to content

stringsplit + stringleft


Recommended Posts

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?

Link to comment
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 :)

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

Link to comment
Share on other sites

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!

Link to comment
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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...