$anytok()

By vaseline28 on Jun 23, 2008

Ever wanted to see if you can match any word in a group with any word in another group with an unspecified number of words?
This does it for you, usage explained below.

; $anytok(text,text to search).prop <-- Searches all of the unspecified amount of text in 'text' for at least 1 match in 'text to search'. PROP << Must be specified as one of the below.
; Usage:
; $anytok(text,text to search,N).all <-- Returns every word matched
; $anytok(text,text to search,N).num <-- Returns numerically, the number of matches found
; $anytok(text,text to search,N).true <-- Returns $true if there is at least one match and $false if there is not one
; Examples:
; $anytok(hi this is good,hi how are you,32).num <-- Returns '1'. .all would return "hi" and .true would return $true

; $anytok(text,text to search).prop <-- Searches all of the unspecified amount of text in 'text' for at least 1 match in 'text to search'.  PROP << Must be specified as one of the below.
; Usage:
; $anytok(text,text to search).all <-- Returns every word matched
; $anytok(text,text to search).num <-- Returns numerically, the number of matches found
; $anytok(text,text to search).true <-- Returns $true if there is at least one match and $false if there is not one
; Examples:
; $anytok(hi this is good,hi how are you).num <-- Returns '1'.  .all would return "hi" and .true would return $true
alias anytok {
  if ($isid) {
    var %x 0
    while (%x < $numtok($1,$3)) {
      inc %x
      $iif($istok($2,$gettok($1,%x,$3),$3),set %z %z $gettok($1,%x,$3),)
    }
    var %t %z | unset %z
    $iif($prop == num,return $numtok(%t,$3),)
    if ($prop == true) {
      $iif(%t,return $true,return $false)
    }
    $iif($prop == all,return %t,)
  }
}

Comments

Sign in to comment.
BlueThen   -  Jul 01, 2008

Ok. :P

 Respond  
vaseline28   -  Jul 01, 2008

Edited that out BlueThen, now explains how PROP must be specified, thanks!

 Respond  
BlueThen   -  Jul 01, 2008

$anytok(text,text to search,N) <-- Searches all of the unspecified amount of text in \'text\' for at least 1 match in \'text to search\' with an ascii character where N is

Edit: Oh. :(

 Respond  
vaseline28   -  Jul 01, 2008

Absolutely nothing, I don\'t see the need to add something, unless you want by default, to get a certain prop return.

I would easily edit that in if someone wanted it.

 Respond  
Lindrian   -  Jul 01, 2008

What happends if $prop == $null?

 Respond  
Jonesy44   -  Jul 01, 2008

looks usefull vaseline! I may use this sometimes soon :P

 Respond  
vaseline28   -  Jul 01, 2008

Edited again: Now actually works!

 Respond  
vaseline28   -  Jun 25, 2008

Thanks, not making much difference though, and the comma in there is good for me if I edit it, easier to see!

Edited: Includes the ability to work for all Ascii characters, not just 32.

 Respond  
Typo   -  Jun 24, 2008

I cant imagine at this moment what I would use this for but it looks good.

btw your
$iif(v1 -- v2,T,)
doesnt require the trailing , when not assigning F like you did, i.e.
$iif(v1 -- v2,T)
would be the same, atleast in my experience.

score = 7/10

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.