mIRC Home    About    Download    Register    News    Help

Print Thread
#198830 05/05/08 02:28 AM
A
AWEstun
AWEstun
A
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'?

#198832 05/05/08 04:25 AM
Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
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)


A
AWEstun
AWEstun
A
Thank you.

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

#198846 05/05/08 12:15 PM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
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.

Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
Sidenote:
//echo -a $asc($?)
can be used for those characters that cannot be used directly in $asc().

A
AWEstun
AWEstun
A
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)?

#198853 05/05/08 01:42 PM
Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
/help $replace

A
AWEstun
AWEstun
A
Thanks.


Link Copied to Clipboard