mIRC Home    About    Download    Register    News    Help

Topic Options
#218580 - 18/02/10 11:37 PM How do I parse symbols?
StrawberryKitty Offline
Ameglian cow

Registered: 04/06/09
Posts: 48
I wanna parse symbols in mirc, well replace them with underscores. I tried this:

Quote:
alias replaceIt {
return $replace($1-,$chr(96),_,$chr(126),_,$chr(33),_,$chr(64),_,$chr(35),_,$chr(36),_,$chr(37),_,$chr(94),_,$chr(38),_,$chr(42),_,$chr(40),_,$chr(41),_,$chr(45),_,$chr(43),_,$chr(61),_,$chr(123),_,$chr(125),_,$chr(91),_,$chr(93),_,$chr(92),_,$chr(124),_,$chr(59),_,$chr(58),_,$chr(39),_,$chr(34),_,$chr(44),_,$chr(46),_,$chr(60),_,$chr(62),_,$chr(47),_,$chr(63))
}


But all I get is:

Quote:
* Invalid parameters: $replace


How do I do this?

Top
#218581 - 19/02/10 12:05 AM Re: How do I parse symbols? [Re: StrawberryKitty]
extremity Offline
Pikka bird

Registered: 05/01/10
Posts: 11
You have an odd number of parameters. Add another ,_ after your last $chr(63).

So it would be:

Code:
alias replaceIt {
  return $replace($1-,$chr(96),_,$chr(126),_,$chr(33),_,$chr(64),_,$chr(35),_,$chr(36),_,$chr(37),_,$chr(94),_,$chr(38),_,$chr(42),_,$chr(40),_,$chr(41),_,$chr(45),_,$chr(43),_,$chr(61),_,$chr(123),_,$chr(125),_,$chr(91),_,$chr(93),_,$chr(92),_,$chr(124),_,$chr(59),_,$chr(58),_,$chr(39),_,$chr(34),_,$chr(44),_,$chr(46),_,$chr(60),_,$chr(62),_,$chr(47),_,$chr(63),_)
}


Top
#218582 - 19/02/10 01:06 AM Re: How do I parse symbols? [Re: StrawberryKitty]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
Note that you're much better off with a regex:

Code:
//echo -a $regsubex(Hello !._~/ world,/[^a-z0-9 ]/ig,_)
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#218584 - 19/02/10 01:19 AM Re: How do I parse symbols? [Re: StrawberryKitty]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
Dunno if this is of use at all... laugh

Your $chrs
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 58 59 60 61 62 63 64 91 92 93 94 96 123 124 125 126
equal the octals
41 42 43 44 45 46 47 50 51 52 53 54 55 56 57 72 73 74 75 76 77 100 133 134 135 136 140 173 174 175 176

So you alternatively could use:
Code:
alias replaceIt2 { return $regsubex(repit,$1-,/[\41-\47\50-\57\72-\77\100\133-\136\140\173-\176]/g,_) }


But as $mknickfn() of your symbol string
Code:
!"#$%&'()*+,-./:<=>?@[\]^`{|}~
is:
Code:
_______()___-_________[_]^`{_}_
you'd only have to replace the remaining chars: ()-[]^`{}
For example:
Code:
alias replaceIt3 { return $regsubex(repit,$mknickfn($1-),/[\50\51\55\133\135\136\140\173\175]/g,_) }
which is the same as
Code:
alias replaceIt4 { return $regsubex(repit,$mknickfn($1-),/[()\-[\]^`{}]/g,_) }
(note that the "]" and "-" in the character class require escapes... that's why I prefered to work with octals)

However, $mknickfn() will replace additional chars, more than given in your alias. Only the "replaceIt2"-alias will exactly do the same as your - completely valid - $replace-approach.

Edit: like argv0 points out, it all depends on whether you want to replace a specific set of chars, or everything BUT a specific set of chars.

Top
#218587 - 19/02/10 04:05 AM Re: How do I parse symbols? [Re: StrawberryKitty]
StrawberryKitty Offline
Ameglian cow

Registered: 04/06/09
Posts: 48
Thanks guys but still having problems here.

Quote:
alias replaceIt {
return $replace($1-,$chr(96),_,$chr(126),_,$chr(33),_,$chr(64),_,$chr(35),_,$chr(36),_,$chr(37),_,$chr(94),_,$chr(38),_,$chr(42),_,$chr(40),_,$chr(41),_,$chr(45),_,$chr(43),_,$chr(61),_,$chr(123),_,$chr(125),_,$chr(91),_,$chr(93),_,$chr(92),_,$chr(124),_,$chr(59),_,$chr(58),_,$chr(39),_,$chr(34),_,$chr(44),_,$chr(46),_,$chr(60),_,$chr(62),_,$chr(47),_,$chr(63),_)
}

alias replaceIt2 { return $regsubex(repit,$1-,/[\41-\47\50-\57\72-\77\100\133-\136\140\173-\176]/g,_) }

alias replaceIt3 { return $regsubex(repit,$mknickfn($1-),/[\50\51\55\133\135\136\140\173\175]/g,_) }

alias replaceIt4 { return $regsubex(repit,$mknickfn($1-),/[()\-[\]^`{}]/g,_) }


Quote:
//echo 4 -a Test: $replaceIt(` ~ ! @ # $ % ^ & * ( ) - + = { } [ ] \ | ; : ' " , . < > / ?)
//echo 4 -a Test: $replaceIt2(` ~ ! @ # $ % ^ & * ( ) - + = { } [ ] \ | ; : ' " , . < > / ?)
//echo 4 -a Test: $replaceIt3(` ~ ! @ # $ % ^ & * ( ) - + = { } [ ] \ | ; : ' " , . < > / ?)
//echo 4 -a Test: $replaceIt4(` ~ ! @ # $ % ^ & * ( ) - + = { } [ ] \ | ; : ' " , . < > / ?)


Quote:
-
* Invalid format: $replaceIt
-
* Invalid format: $replaceIt2
-
* Invalid format: $replaceIt3
-
* Invalid format: $replaceIt4
-


I hate parsing x.x

Top
#218588 - 19/02/10 04:44 AM Re: How do I parse symbols? [Re: StrawberryKitty]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
using a , inside an identifier will confuse mIRC, use $chr(44) instead.

I highly suggest using my regex, its far simpler than any of the others provided.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#218589 - 19/02/10 05:29 AM Re: How do I parse symbols? [Re: StrawberryKitty]
StrawberryKitty Offline
Ameglian cow

Registered: 04/06/09
Posts: 48
I can't do that because the input I'm reciving has it I can't tell the input please use $chr() that's why it needs to be parased somehow.

Top
#218590 - 19/02/10 05:47 AM Re: How do I parse symbols? [Re: StrawberryKitty]
StrawberryKitty Offline
Ameglian cow

Registered: 04/06/09
Posts: 48
Going into more detail about this issue

Code
Quote:
alias replaceIt {
return $replace($1-,$chr(96),_,$chr(126),_,$chr(33),_,$chr(64),_,$chr(35),_,$chr(36),_,$chr(37),_,$chr(94),_,$chr(38),_,$chr(42),_,$chr(40),_,$chr(41),_,$chr(45),_,$chr(43),_,$chr(61),_,$chr(123),_,$chr(125),_,$chr(91),_,$chr(93),_,$chr(92),_,$chr(124),_,$chr(59),_,$chr(58),_,$chr(39),_,$chr(34),_,$chr(44),_,$chr(46),_,$chr(60),_,$chr(62),_,$chr(47),_,$chr(63),_)
}


Test Command
Quote:
//echo 4 -a Char: $replaceIt()


Results
Quote:
` Char: _
~ Char: _
! Char: _
@ Char: _
# Char:
$ Char: _
% Char: _
^ Char: _
& Char: _
* Char: _
( * Invalid format: $replaceIt
) Char:
- Char: _
+ Char: _
= Char: _
{ Char:
} Char:
[ Char: _
] Char: _
\ Char: _
| Char: _
; Char: _
: Char: _
' Char: _
" Char: _
. Char: _
< Char: _
> Char: _
/ Char: _
? Char: _
[ ] Char:
{ } Char:


Can't really thing of any other things mirc can't process


Edited by StrawberryKitty (19/02/10 05:51 AM)

Top
#218591 - 19/02/10 06:27 AM Re: How do I parse symbols? [Re: StrawberryKitty]
StrawberryKitty Offline
Ameglian cow

Registered: 04/06/09
Posts: 48
After lots of testing.

Mirc can parse these:
Quote:
` ~ ! @ ^ & * - + = \ ; : ' " . < > / ?


Mirc cannot parse these:
Quote:
# $ % ( ) { } [ ] | ,


Note: Some things I've listed in cannot parse can be parsed on their own but with other characters they can't.


Edited by StrawberryKitty (19/02/10 06:34 AM)

Top
#218592 - 19/02/10 07:37 AM Re: How do I parse symbols? [Re: StrawberryKitty]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
Slow down.

You're confusing the issue.

I'm not sure this can be explained in one message, but I'll try.

mIRC, like any programming language, has "special" characters that have syntactical meaning to how the language works.

The symbols you listed that mIRC "can't parse" are a list of those very special symbols. You cannot use those characters literally in your scripts. You must escape them. One way to escape a special character is to use $chr(N) where N is the ASCII value of the character. This is why I suggested using $chr(44) for the comma. Similarly, if you want to use a "#", you must use $chr(35).

Try it: //echo -a $chr(35) # $chr(44) ,

Note that , is a bad example above, since it only has special meaning inside an identifier (like $nick(#,N))

Now... going back to the important word I used above, literally: these characters are special characters only when they appear literally in your code. If they come from input like $1-, they are not literals, and are not treated specially.

When you said "I can't tell people to use $chr(44)" you were once again confused. You need not tell people to use $chr(44).

Try it: //tokenize 32 a , b , c | echo -a $remove($1-,$chr(44))

The above will remove all commas from the text. Note that you cannot use the literal "," in the $remove, you will confuse mIRC syntactically.

This means you can't directly tell mIRC to do: $replaceIt(,)

But you can use a , when taken from a %variable or $1-:

//var %x = , | echo -a $replaceIt(%x)

Basically, your alias works fine (I still recommend using a regex). You only think it's broken because you're testing it incorrectly.

Hope that clarifies the issue. There are no problems with reading character input in mIRC, it all depends how you do it.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#218596 - 19/02/10 08:40 AM Re: How do I parse symbols? [Re: StrawberryKitty]
StrawberryKitty Offline
Ameglian cow

Registered: 04/06/09
Posts: 48
This still falls apart for me cause I can't think of a work around for every character mirc sees as special espically

Example:
Quote:
//tokenize 32 a | b | c | | echo -a $remove($1-,$chr(124))


Decided to wikipedia mirc scripting language too

mIRC Scripting lanugage Limitations

I'm guessing I'm running into the second limitation -.-

Top
#218597 - 19/02/10 08:44 AM Re: How do I parse symbols? [Re: StrawberryKitty]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
Yes, you are running into that limitation, and I told you how to get around it; escape the special characters instead of using them literally.

//tokenize 32 a $chr(124) b $chr(124) | echo -a $1-

Note that this limitation is not unique to mIRC. This is the same issue as in the regular expression syntax. For instance, you cannot have the regular expression matching [] without escaping the [] characters, since they have special meaning in regex syntax. The means for escaping in regex is \[, in mIRC, it's common to use $chr().
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#218598 - 19/02/10 08:54 AM Re: How do I parse symbols? [Re: StrawberryKitty]
5618 Offline
Hoopy frood

Registered: 18/06/07
Posts: 933
Yes, you're again using special characters (in this case pipes) literally in a command line.
See the difference when you do:

Code:
/set -u60 %a a | b | c | |
//echo -a $remove(%a,$chr(124))

This is how mIRC will also behave when it processes input in remote scripts (where interpretation is (mostly) not literal as in command line).

Top
#218599 - 19/02/10 08:58 AM Re: How do I parse symbols? [Re: 5618]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
That's a very confusing example. /set is allowed to use literals in this case, even though we said you can't. It can because it is only using one /, as opposed to two. Commands typed with one / in the editbox are not parsed by the script parser, so literals are okay.

Code:
/set %a a | b | c
//echo -a %a
//set %b a | b | c
//echo -a %b


Note the difference.

In the script editor, however, all commands are executed as if they were typed with //, regardless of how many /'s you use in your commands in an event/alias. If you understood the explanation above it should be clear as to why.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#218600 - 19/02/10 09:10 AM Re: How do I parse symbols? [Re: argv0]
5618 Offline
Hoopy frood

Registered: 18/06/07
Posts: 933
You're right of course.

My example is meant to show that when the input comes from - call it - an indirect source (meaning not from command line; in this case a pre-set variable, but it can also be $1- in a script event), that in those cases symbols are not interpreted as script syntax.

I'll try not to confuse people here. ;-)

Top
#218601 - 19/02/10 09:36 AM Re: How do I parse symbols? [Re: StrawberryKitty]
StrawberryKitty Offline
Ameglian cow

Registered: 04/06/09
Posts: 48
Thanks everyone I finally got my head around it.

Quote:
on *:TEXT:*:#testchannel: {
msg $chan $replace($1-,$chr(96),_,$chr(126),_,$chr(33),_,$chr(64),_,$chr(35),_,$chr(36),_,$chr(37),_,$chr(94),_,$chr(38),_,$chr(42),_,$chr(40),_,$chr(41),_,$chr(45),_,$chr(43),_,$chr(61),_,$chr(123),_,$chr(125),_,$chr(91),_,$chr(93),_,$chr(92),_,$chr(124),_,$chr(59),_,$chr(58),_,$chr(39),_,$chr(34),_,$chr(44),_,$chr(46),_,$chr(60),_,$chr(62),_,$chr(47),_,$chr(63),_)

}

Quote:
<TestClient545> (` ~ ! @ # $ % ^ & * ( ) - + = { } [ ] \ | ; : ' " , . < > / ?)
<@StrawberryKitty> __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __

Top
#218723 - 23/02/10 09:05 AM Re: How do I parse symbols? [Re: StrawberryKitty]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
StrawberryKitty, there's nothing wrong with the code Horstl provides for you. With a little revamp of it, here is all you need to replace all the characters with the underscore as you've mentioned:
Code:
on $*:text:/[\41-\47\50-\57\72-\77\100\133-\136\140\173-\176]/:#: { 
  .msg # $regsubex($1-,/[\41-\47\50-\57\72-\77\100\133-\136\140\173-\176]/g,_)
}
This does exactly the same thing compared to your example of using $replace(), which takes longer and more bytes. Best yet, even in a sentence that consists of any of those characters will be replaced with the underscore. Other normal text won't be effected.

I'll suggest that you use a custom text event instead of the default one to display the result. A custom text event will look like this:
Code:
on ^$*:text:/[\41-\47\50-\57\72-\77\100\133-\136\140\173-\176]/:#: { 
  echo -bfilmrt # $+(<,$nick(#,$nick).pnick,>) $regsubex($1-,/[\41-\47\50-\57\72-\77\100\133-\136\140\173-\176]/g,_) | haltdef
}
You might want to cover the on action or notice event if needed.

Top