Sign in to follow this  
Followers 0
copyright

String Handling !

8 posts in this topic

I went through the help file and did tests.. . and i just can't get what i need. perhaps one of you autoit geniuses can help: ok on the chat i have this..

style 1:

copyright (Uptime: 01:43:13, 67 msgs sent) from 76.216.66.114  24 files

style 2:

copyright (Uptime: 01:53:57, 29 msgs sent) from 76.216.66.114

style 3:

copyright: 76.216.66.114 Last seen 09/22/2004 07:57:13

the three different whois's.. how is it possible to store "only" the ip address of the user in each of these cases.

if it helps i noticed theres always two spaces in between the ip address and the number of files the user has in the first style.. but then again, i could always be wrong..

i just need three different examples for each case! please, thanks a bunch guys! what would be the most accurate way of getting just the ip..

Share this post


Link to post
Share on other sites



I went through the help file and did tests.. . and i just can't get what i need. perhaps one of you autoit geniuses can help: ok on the chat i have this..

style 1:

copyright (Uptime: 01:43:13, 67 msgs sent) from 76.216.66.114  24 files

style 2:

copyright (Uptime: 01:53:57, 29 msgs sent) from 76.216.66.114

style 3:

copyright: 76.216.66.114 Last seen 09/22/2004 07:57:13

  the three different whois's.. how is it possible to store "only" the ip address of the user in each of these cases.

  if it helps i noticed theres always two spaces in between the ip address and the number of files the user has in the first style.. but then again, i could always be wrong..

  i just need three different examples for each case! please, thanks a bunch guys! what would be the most accurate way of getting just the ip..

<{POST_SNAPBACK}>

hmmm... maybe a select case, where you check the format with the three know variations and then do a string strip based on that?

Select
case StringInStr($string, "sent) from ");in the case of this format: "copyright (Uptime: 01:43:13, 67 msgs sent) from 76.216.66.114  24 files"
  ;do some string trims to get the ip
EndSelect

with cases for each possible format?


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

StringSplit() the line by space, then in the new array, test each element for having 3 periods using StringInStr(). The one with 3 periods is the element you want.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Following should work if the only time a dot appears in the string is inside an IP Address and if there is always a space before and after the address:

MsgBox(4096,"one", parseIP("copyright (Uptime: 01:43:13, 67 msgs sent) from 76.216.66.114  24 files"))
MsgBox(4096,"two", parseIP("copyright (Uptime: 01:53:57, 29 msgs sent) from 76.216.66.114 "))
MsgBox(4096,"three", parseIP("copyright: 76.216.66.114 Last seen 09/22/2004 07:57:13"))
Exit

Func parseIP($str)
   $str = $str & " "; quick hack to make the second case works
   
 ; Get occurrance of first dot in string
   Local $dotPos = StringInStr($str, ".")
   
 ; Get first space closest to that dot
   Local $spacePos = $dotPos
   While $spacePos > 1
      $spacePos = $spacePos - 1
      If StringMid($str, $spacePos, 1) = " " Then ExitLoop
   Wend
   
 ; Read from that position to the next space
   $endPos = StringInStr( StringTrimLeft($str, $spacePos) , " ")
   Return StringMid($str, $spacePos, $endPos)
EndFunc

Edit: Er, use Valik's method :ph34r:

Func valik($str)
   Local $a = StringSplit($str, " ")
   For $i = 1 to $a[0]
      If _StringCount($a[$i], ".") = 3 Then Return $a[$i]
   Next
   Return ""
EndFunc

; helper function... why isn't this built in to AutoIt???
func _stringcount($Si,$Sf)
if stringlen($Sf)<1 then exit
$ts = StringSplit(stringreplace($Si,$Sf,chr(01)),chr(01))
 return($ts[0]-1)
endfunc
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Or (Untested)...

Func ParseIP($string)
    Dim $a = StringSplit($string, " ")
    Local $i
    For $i = 1 To $a[0]
        If StringInStr($a[$i], ".", 0, 3) Then Return $a[$i]
    Next
    Return ""
EndFunc

Share this post


Link to post
Share on other sites

Or (Untested)...

Func ParseIP($string)
    Dim $a = StringSplit($string, " ")
    Local $i
    For $i = 1 To $a[0]
        If StringInStr($a[$i], ".", 0, 3) Then Return $a[$i]
    Next
    Return ""
EndFunc

<{POST_SNAPBACK}>

I tested it, it works. RIght on. I'll save that one for later....

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

I tested it, it works.  RIght on.  I'll save that one for later....

<{POST_SNAPBACK}>

soooo..... what variable do i use to controlsend it to a window ?

Share this post


Link to post
Share on other sites

Whatever variable you use to capture the return value of the function.

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