|
Joined: May 2006
Posts: 122
Vogon poet
|
OP
Vogon poet
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.
|
|
|
|
Joined: Feb 2005
Posts: 342
Fjord artisan
|
Fjord artisan
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. 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, 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.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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)
|
|
|
|
Joined: Feb 2005
Posts: 342
Fjord artisan
|
Fjord artisan
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?
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
I think you misunderstood me :tongue: To demonstrate what I mean, type the following: //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: alias t {
var %text = a b c d, %pos = 3
var %word = $gettok($left(%text,%pos),-1,32)
echo -a %word
} /t
|
|
|
|
Joined: Feb 2005
Posts: 342
Fjord artisan
|
Fjord artisan
Joined: Feb 2005
Posts: 342 |
No, I know how it works. Here, to better demonstrate it with YOUR code, modified to show part of a word. This gets the position of "b" 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.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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)
|
|
|
|
Joined: Feb 2005
Posts: 342
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: May 2006
Posts: 122
Vogon poet
|
OP
Vogon poet
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.
|
|
|
|
|