mIRC Home    About    Download    Register    News    Help

Print Thread
#198830 05/05/08 02:28 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
How do I use $left or $mid or $right to extract a part of a string? Say %abc = sam[test@1.2.3.4] How would I use $left to extract 'sam' and $mid to extract 'test' and $right to extract '1.2.3.4'?


I registered; you should too.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Unless you can guarantee that
1) SAM is always going to be 3 characters
2) there will only be 1 character between SAM and TEST
3) 1.2.3.4 will always be 7 characters
4) there will always be 1 character at the end
then I would not recommend even trying to use $left, $mid, $right

A much more flexible set of options exists using token identifiers

Code:
;set variable abc to sam[test@1.2.3.4]
%abc = sam[test@1.2.3.4]
;set %nick to match the characters starting from the beginning of the variable %abc to the first occurance of ascii character 91 (aka [)
%nick = $gettok(%abc,1,91)
;set %ident to match the characters starting from the beginning of the variable %abc to the first occurance of ascii character 64 (aka @)
%ident = $gettok(%abc,1,64)
;set %ident to match the characters going from the end of %ident to the first occurance of ascii character 91
%ident = $gettok(%ident,-1,91)
;set %host to match the characters going from the end of %abc to the first occurance of ascii character 64
%host = $gettok(%abc,-1,64)
;set %host to match the characters going from the beginning of %host to the first occurance of ascii character 93 (aka ])
%host = $gettok(%host,1,93)


I have included detailed explanations as to how each step in the code would proceed, due to the fact that you have been referred to token identifiers previously and are still trying to get the information the hard way.

To summarize the above code
Code:
%abc = sam[test@1.2.3.4]
%nick = $gettok(%abc,1,91)
%ident = $gettok($gettok(%abc,1,64),-1,91)
%host = $gettok($gettok(%abc,-1,64),1,93)


Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thank you.

In '%ident = $gettok(%abc,1,64)' how would I go about changing the '[' to a '!'?


I registered; you should too.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Use //echo -a $asc(!) to find out what number to use instead of 64. Replace ! with almost any character to get the ascii value you need. Certain characters that are used in mIRC's scripting engine won't work from $asc, such as a comma, but most will. A comma is 44, btw.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Sidenote:
//echo -a $asc($?)
can be used for those characters that cannot be used directly in $asc().


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
I think I asked the wrong thing. What I meant to ask is say I have a string like:

apple[12345678_12345678

What command would I use to change the [ (ascii 91) to a ! (ascii 44)?


I registered; you should too.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
/help $replace


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thanks.


I registered; you should too.

Link Copied to Clipboard