mIRC Home    About    Download    Register    News    Help

Print Thread
Ansi 2 mIRC #57334 25/10/03 05:37 AM
Joined: Dec 2002
Posts: 68
P
phrozenfire Offline OP
Babel fish
OP Offline
Babel fish
P
Joined: Dec 2002
Posts: 68
I have text like this:

Code:
You see exits leading northeast, south, and northwest.


I need to detect all the ANSI codes (they all look like  or similar), and then return the whole phrase in mIRC codes (using the identifier $ansi2mirc). Where there is a different ANSI code, it needs to find the new color for when it changes, so there could be several different ANSI codes in a sentence, meaning that there would be several different colors. It has to find all of them. Thanks.

Note: Putting the whole thing, if there is more than once ANSI code, into $ansi2mirc returns an error, so that's not a possibility.


Re: Ansi 2 mIRC #57335 25/10/03 08:30 AM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
ok, I'm not the world's best with regular expressions, but set your whole line in a variable called %txt and apply the following line to count how many times they format [N;NNm makes an appearance.
Code:
$regex(%txt,/(\[[0-9];[0-9]{2}m)/g)

The problem is $ansi2mirc([1;34m) returns [1;34m for mem, so I'm probably doing something wrong in detecting the ansi code.

You can use this as a basis for a $regsub, to replace the ansi code with $ansi2mirc(ansicode)


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: Ansi 2 mIRC #57336 25/10/03 02:58 PM
Joined: Dec 2002
Posts: 68
P
phrozenfire Offline OP
Babel fish
OP Offline
Babel fish
P
Joined: Dec 2002
Posts: 68
You need a $chr(27) before the [#;##m. You might need to change your code, I'm not sure.

Re: Ansi 2 mIRC #57337 25/10/03 03:09 PM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
Ok, this is not the most beautiful, and a $regsub will probably be faster, but this works:

set your line into a variable called %txt
Code:
alias tst {
  var %i = $regex(%txt,/(\[[0-9];[0-9]{2}m)/g)
  while (%i >= 1) {
    %txt = $replace(%txt,$regml(1),$ansi2mirc($regml(1)))
    %i = $regex(%txt,/(\[[0-9];[0-9]{2}m)/g)
  }
  echo -a %txt
}


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: Ansi 2 mIRC #57338 25/10/03 03:14 PM
Joined: Dec 2002
Posts: 68
P
phrozenfire Offline OP
Babel fish
OP Offline
Babel fish
P
Joined: Dec 2002
Posts: 68
I totally forgot to point this out, sometimes the ";" is not there. Example:

Code:
The bright sun shines down, blanketing you with its life-giving warmth. A runic


If somebody could fix the code above, that would be awesome. Thanks.

Re: Ansi 2 mIRC #57339 25/10/03 03:39 PM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
replace the regex with
Code:
$regex(%txt,/(\[[0-9]?;?[0-9]{2}m)/g)

or so I'm told


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: Ansi 2 mIRC #57340 25/10/03 04:23 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
Note: Putting the whole thing, if there is more than once ANSI code, into $ansi2mirc returns an error, so that's not a possibility.

I'll take a guess here but try this:
Code:
//var %a = You see exits leading northeast, south, and northwest. | echo -a $ansi2mirc(%a)
The reason that it errors could be the commas in the string. Commas are used for separating parameters in identifiers: if put directly in $ansi2mirc() mirc thinks you're passing more than one parameters to it, so it errors.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Ansi 2 mIRC #57341 25/10/03 08:54 PM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
Which is why I suggested he put the string in a variable and use the variable in the #regex...


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: Ansi 2 mIRC #57342 26/10/03 01:19 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
If you agree that the commas was the cause of the error, why did you post the regex solution? What I'm saying is that it's possible that $ansi2mirc only returned an error because of the commas in the string, not because it doesn't support more than one codes in the input. $ansi2mirc does support multiple codes (compare the outputs of $ansi2mirc(%txt) and /tst, you'll see they're the same), which means that the regex isn't needed.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Ansi 2 mIRC #57343 26/10/03 07:34 AM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
I said the regex coukldn't deal with comma's in the string =which is true=. I did not say that $ansi2mirc(string) wouldn't work, the original poster did (see original post, bottom line). I never said commas were the problem in $ansi2mirc (but they will be - mirc identifiers cannot deal with comma's in text strings since comma's are used to separate arguments), when I said comma's would give a problem, I was referring to the regex.


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius