mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
im trying to write an alias that will delete the last charachter/numberic or char in a variable
like example

if the varable is called %myvar and it has 1 2 3 4

%myvar 1 2 3 4
and you wanted to delete the 4 after, (not cause it was a 4, just cause it was the last char)

is there an easy way to create a alias that will delete the last charachter in a variable?

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
//set %myvar $gettok(%myvar,$+(1,-,$calc($numtok(%myvar,32) - 1)),32)

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
//set %var $deltok(%var,-1,32)

Btw to the OP: I think you are confusing a char with a token (they can be the same but not necessarily). What if the %var was 10 20 30, taking out the last char would mean taking out the 0 from 30, but taking out the last space delimited token would mean taking out the 30. The current solution with $deltok takes out a token. A char based solution would be something like //set %var $left(%var,-1)


Gone.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Or that, but I've always done things the hard way.. :tongue:

Joined: May 2005
Posts: 449
Fjord artisan
Offline
Fjord artisan
Joined: May 2005
Posts: 449
LOL, and I would have gone with $remove(%myvar,$right(%myvar,1)). smile

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
But supposing you have numbers in %myvar 1-10.

/set %myvar 1 2 3 4 5 6 7 8 9 10

//echo -a $remove(%myvar,$right(%myvar,1))

You'll get 1 2 3 4 5 6 7 8 9 1

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I know you didn't propose $remove as a solution, so it's no offense or anything, but I'd like to point out why exactly $remove is a bad idea to use in cases such as these and similar.

Say his var was:

%var 10 15 16 11

$right(%var,1) = 1
$remove(%var,1) = 0 5 6

In other words, that would screw up the entire variable rather than just delete the last char. In general, one should only use $remove if one doesn't mind all occurences to be removed. If you want to only delete certain matches, then $remove is a not the way to go.


Gone.
Joined: May 2005
Posts: 449
Fjord artisan
Offline
Fjord artisan
Joined: May 2005
Posts: 449
True, didn't think of that. I guess that's why you have almost 3000 more posts than I do! grin

Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
Thanks it works perfect smile
you guys are always awesome

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
3? :tongue:


Link Copied to Clipboard