Sign in to follow this  
Followers 0
Prodigus

How would I trim this?

10 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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


Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$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

Share this post


Link to post
Share on other sites

Fancy, I didn't know you could concatenate them like that.

Yup. :D

We were posting at the same time so I didn't see yours until I posted mine, hehe.


Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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.

Share this post


Link to post
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

Share this post


Link to post
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


Share this post


Link to post
Share on other sites

Thanks!!!!!

Solves a big problem I was having......

Share this post


Link to post
Share on other sites

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

that is a nice, new one to me too!!

8)


NEWHeader1.png

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