mIRC Home    About    Download    Register    News    Help

Print Thread
#155513 07/08/06 10:42 AM
Joined: May 2006
Posts: 122
J
jizzy Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2006
Posts: 122
Say I have a line of text "my name is jizzy how are u"
The 13 character is z and is in the 4th token using chr 32.
How can i dynamically find out which token the 13th character is in?


If only women came with popup menus and online help.
#155514 07/08/06 11:03 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
I'm assuming you're trying to do an "on tabcomp" script?

There's an easy way to do it with on tabcomp.

Code:
on *:TABCOMP:*:{
  var %a = $active , %pos = $editbox(%a).selend - 1 , %z = $left($1-,%pos)
  var %word = $gettok(%z,$gettok(%z,0,32),32)
  echo -ag %word
}


Just an example. Doesn't contain any error checking.

Otherwise,

Code:
alias tehword {
  if ($0 > 2) {
    var %letter = $1 , %num = $2 , %text = $3-
    var %pos = $pos(%text,%letter,%num)
    var %word = $gettok($left(%text,%pos),0,32)
    var %word = $gettok(%text,%word,32)
    $iif($isid,return,echo -ag) %word
  }
}


/tehword <letter> <number> <text>

/tehword o 1 This is just an example. So you can see how this works.
Returns: "So"

Changing 1 to 2 returns: you
Changing 2 to 3 returns: how
Changing 3 to 4 returns: works.

#155515 07/08/06 11:08 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Just to let you know, you can use $gettok(%z,-1,32) instead of $gettok(%z,$gettok(%z,0,32),32) smile

#155516 07/08/06 11:30 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Uh, unfortunately that doesn't really apply here, unless I'm missing something? -1 would be assuming that we know the entirety of the last word. He wants to grab a letter, and find the word it belongs to, meaning it could be in the middle of the sentence, and in the middle of a word.

The $gettok($left(%text,%pos),0,32) is necessary to do this. As we need to find out how many tokens are between the beginning, and the specified letter position. So we set it to it to a var, and then use it on the entire %text, to get the full word.

You tired hixxy? grin

#155517 07/08/06 11:40 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I think you misunderstood me :tongue:

To demonstrate what I mean, type the following:

Code:
//var %z = hello world blah blah x | echo -a $gettok(%z,-1,32) ~ $gettok(%z,$gettok(%z,0,32),32)


You could also apply this to the two %word variables you're using:

Code:
alias t {
  var %text = a b c d, %pos = 3
  var %word = $gettok($left(%text,%pos),-1,32)
  echo -a %word
}


/t

#155518 07/08/06 11:45 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
No, I know how it works. wink

Here, to better demonstrate it with YOUR code, modified to show part of a word. This gets the position of "b"

Code:
alias xt {
  var %text = aaa bbb ccc ddd, %pos = 5
  var %word = $gettok($left(%text,%pos),-1,32)
  echo -a %word
}


/xt

That returns just "b"

You must be tired. :P

But yes, I already know about -1.

#155519 07/08/06 11:47 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Oh yes, I see what you're doing now with the %text/%word vars, but I'm right about %z. $gettok(%z,$gettok(%z,0,32),32) = $gettok(%z,$numtok(%z,32),32) = $gettok(%z,-1,32)

#155520 07/08/06 11:53 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Haha, yes. That works fine to get the last word in a %var. That's why I was saying -1 doesn't really help here. I've used it a few times before, though, since I usually don't need to get just the last word it's not something I use very often. I knew what you meant.

Though, I could have used $numtok() in there instead. Almost 7am, I'm tired too.

#155521 07/08/06 02:03 PM
Joined: May 2006
Posts: 122
J
jizzy Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2006
Posts: 122
Ahh, I was close except I was just using gettok on the line that had been cut, rather than using it to find the token number. Silly me. Thanx for the fast replies guys, cheers :P


If only women came with popup menus and online help.

Link Copied to Clipboard