Jump to content

How would I trim this?


Recommended Posts

I just want to grab the IP address out of this string

6/4/2006 12:10:46 PM | 23T7111.my.com (10.100.51.194) is alive.

I would thing there would be a function where I could just grab whatever is between "(" and ")"

Is there?

The count would be different from left or right depending on the date and the IP address so I didn't think I could do it with a StringTrimLeft or right...

Link to comment
Share on other sites

I just want to grab the IP address out of this string

6/4/2006 12:10:46 PM | 23T7111.my.com (10.100.51.194) is alive.

I would thing there would be a function where I could just grab whatever is between "(" and ")"

Is there?

The count would be different from left or right depending on the date and the IP address so I didn't think I could do it with a StringTrimLeft or right...

Check out StringSplit in the helpfile for more info on how this works...

$string = "6/4/2006 12:10:46 PM | 23T7111.my.com (10.100.51.194)"

$Split = StringSplit ( $string, "(" )
$Split2 = StringSplit ( $Split[2], ")" )

MsgBox ( 0, "", $Split2[1] )
Edited by exodius
Link to comment
Share on other sites

$String = StringSplit ( "6/4/2006 12:10:46 PM | 23T7111.my.com (10.100.51.194) is alive.", "(" & ")")
MsgBox(0, "Return", $String[2])

Enjoy,

Nomad :D

Fancy, I didn't know you could concatenate them like that. I understand how splitting the string at "(" gives you [2], but wouldn't you need the [1] of ")"? Edited by exodius
Link to comment
Share on other sites

I would prefer to use stringbetween. They produce the same results and stringbetween is easier to use.

$string = "6/4/2006 12:10:46 PM | 23T7111.my.com (10.100.51.194) is alive."
$ip = StringSplit ( $string, "()")
MsgBox(0, "StringSplit", "The ip is: " & $ip[2])
MsgBox(0, "StringBetween", "The ip is: " & _StringBetween($string, "(", ")"))

Func _StringBetween($s, $from, $to)
    $x = StringInStr($s, $from) + StringLen($from)
    $y = StringInStr(StringTrimLeft($s, $x), $to)
    Return StringMid($s, $x, $y)
EndFunc
Edited by RazerM
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Fancy, I didn't know you could concatenate them like that. I understand how splitting the string at "(" gives you [2], but wouldn't you need the [1] of ")"?

Just came to the realization that concatenating them like that splits the string up based upon those two characters instead of just one. :D
Link to comment
Share on other sites

Just came to the realization that concatenating them like that splits the string up based upon those two characters instead of just one. :D

I had to do a lot of string extracting not too long ago, so I got a lot of experience with using that command. Saved me a lot of lines in my script. :D

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...