This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Please help with this character ( ¤)

Help for those learning Tcl or writing their own scripts.
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Please help with this character ( ¤)

Post by Reynaldo »

Code: Select all

if {[string match -nocase "*¤*" $rname] == 1 || [string length $rname] > 45} { .... }
any idea how to detect that chars "¤" it doesn't work, but in my mirc scritps it's working well.

it mirc, the chars in $chr(164) will return to "¤" , i have no idea in tcl, seems so confusing.

Code: Select all


if ($chr(164) isin $9-) { .... }
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

format {%c} "164"
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Code: Select all

if {[string match "*\xA4*" $rname] || [string length $rname] > 45} { .... }
The above should work fine because characters up to hex FF can be represented by using a backslash followed by an x and then the two digit hex number (164 decimal == A4 hex).

[12:51] <arfer> .tcl set varname \xA4
[12:51] <Baal> Tcl: ¤

BTW, you dont need to use == 1 with a string equal / string match. The fact that they return 1 (true) or 0 (false) can be used directly in a 'if' statement. Neither do you need the -nocase option since \xA4 is one specific character ie. it does not have an upper/lower case.
I must have had nothing to do
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

arfer wrote:

Code: Select all

if {[string match "*\xA4*" $rname] || [string length $rname] > 45} { .... }
The above should work fine because characters up to hex FF can be represented by using a backslash followed by an x and then the two digit hex number (164 decimal == A4 hex).

[12:51] <arfer> .tcl set varname \xA4
[12:51] <Baal> Tcl: ¤

BTW, you dont need to use == 1 with a string equal / string match. The fact that they return 1 (true) or 0 (false) can be used directly in a 'if' statement. Neither do you need the -nocase option since \xA4 is one specific character ie. it does not have an upper/lower case.
still the bot cannot detect that character, i've try to use "*\00164*" also not working.
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

TCL_no_TK wrote:

Code: Select all

format {%c} "164"
how to use it?

Code: Select all

if {[string match "*[format {%c} "164"]*" $rname] || [string length $rname] > 45} { .... } 

it's right? thanks for the advice.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

 set rname [format {%c} 164]
 set test [scan $rname %c]
  if {$test == 164} {
   puts "It Worked!"
  }
:P
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

TCL_no_TK wrote:

Code: Select all

 set rname [format {%c} 164]
 set test [scan $rname %c]
  if {$test == 164} {
   puts "It Worked!"
  }
:P

Code: Select all

set rname [format {%c} 164] 
seems it's not working. :(, the character is in $rname.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

:roll:

Code: Select all

 set text "¤ Mp3 ¤ My Song - Yeah, it is.mp3 ¤"
 set string [lindex [split $text] 0]
 set test [scan $string %c]
 if {$test == 164} {
  putlog "detected that $text! starts with ¤ :P"
 }
There's probably a much easyer and better way to do this
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

TCL_no_TK wrote::roll:

Code: Select all

 set text "¤ Mp3 ¤ My Song - Yeah, it is.mp3 ¤"
 set string [lindex [split $text] 0]
 set test [scan $string %c]
 if {$test == 164} {
  putlog "detected that $text! starts with ¤ :P"
 }
There's probably a much easyer and better way to do this
Ok, that can detect if the char is in the first of the chars


set text "Mp3 ¤ My Song - Yeah, it is.mp3 ¤"

return of %c will be 77 of M

set hong [scan [string trimleft [lrange $rname 1 end]] %c]
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Sorry about my earlier post. I should have tested first. I have no clue why it does not work. Other than possible solutions provided by TCL_no_TK methodology, the only way I can get the thing to work is by using a regexp with the actual character in question inside grouping elements ([ and ]), as follows :-

[16:27] <@arfer> % return [regexp -- {[¤]} "bla bla bla bla bla ¤"]
[16:27] <@Baal> 1

What really puzzles me is why none of the following will work :-

[16:29] <@arfer> % return [regexp -- {¤} "bla bla bla bla bla ¤"]
[16:29] <@Baal> 0

[16:29] <@arfer> % return [regexp -- {.*¤.*} "bla bla bla bla bla ¤"]
[16:29] <@Baal> 0

[16:35] <@arfer> % return [regexp -- {\xA4} "bla bla bla bla bla ¤"]
[16:35] <@Baal> 0

[16:36] <@arfer> % return [regexp -- {[\xA4]} "bla bla bla bla bla ¤"]
[16:36] <@Baal> 0

Anyway, the answer to your original query would be :-

Code: Select all

if {([regexp -- {[¤]} $rname]) || ([string length $rname] > 45)} { .... }
I think!

I wouldn't mind some sort of explanation for this myself. Where is our friend nml375 when we need him?
I must have had nothing to do
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

This smells like a character set issue...
All four "non-working" tests evaluate to true under a simple tclsh environment for me. When pasting the same code into a telnet session (still using the very same putty setup), all ¤ are converted to $, causing the patterns with \xA4 to fail, but the others to work...

Doing something as simple as "scan [format %c 164] %c" returns 164, as expected. If I enter the ¤ into the strings and patterns using [format ...], all patterns work without a problem, including the \xA4 ones...
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

nml375 wrote:This smells like a character set issue...
Indeed, this is one of those iso8859-1/utf-8 rendering issues. The easiest way to solve it, is to force the string your comparing against into utf-8. Then always use "\xa4" to do _any_ matching. -- OR-- Simply utf-8 patch your bot with thommey's utf-8 patch...

Code: Select all

** via partyline -- those Â's in the bot's response aren't rendered on IRC, just here on the forum. They make all the difference when matching though.
<speechles> .tcl set text [encoding convertto utf-8 "Mp3 ¤ My Song - Yeah, it is.mp3 ¤"]
<bot> Tcl: Mp3 ¤ My Song - Yeah, it is.mp3 ¤

** A direct match of course fails ....
<speechles> .tcl set b [regexp {¤} $text] 
<bot> Tcl: 0

** Using \xa4 always works no matter where...
<speechles> .tcl set b [regexp {\xa4} $text] 
<bot> Tcl: 1

<speechles> .tcl if {[string match *\xa4* $text]} { set b "works" } { set b "fails" }
<bot> Tcl: works

<speechles> .tcl regexp -- {\xa4(.*?)\xa4} $text -> result
<bot> Tcl: 1

** notice the remnant of that silly  in the output. This is the utf-8 sequence broken by an unpatched bot.  The bottom way fixes this.
<speechles> .tcl set showme $result
<bot> Tcl: My Song - Yeah, it is.mp3 Â

** the trick is use an atom (.) prior to the \xa4 in regexp's
<speechles> .tcl regexp -- {.\xa4(.*?).\xa4} $text -> result
<bot> Tcl: 1

<speechles> .tcl set showme $result
<bot> Tcl: My Song - Yeah, it is.mp3
** perfect!
This is clearly an iso8859-1/utf-8 rendering/matching issue. I've dealt with these before... ;)
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Thanks guys. Thought I was going nuts there for a while.
I must have had nothing to do
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

set rname "bla bla bla bla bla ¤"

Code: Select all

if {[regexp {\xA4} $rname] == 1 || [string length $rname] > 45} {..}
Doesnt works! using eggdrop v1.6.18.
i'm going be silly with this char :(
how about using scan method? just scan the last chars of $name, cause the ugly spammers always(not) have that silly char at the end of their realname
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

You were already told how to make it work my man. Use "convertfrom utf-8" instead of "convertto utf-8" and it works without artifcating in those  remnants into the string.

Code: Select all

<speechles> .tcl set rname [encoding convertfrom utf-8 "bla bla bla bla bla ¤"]
<bot> Tcl: bla bla bla bla bla ¤

<speechles> .tcl set result [regexp -- {\xa4} $rname]
<bot> Tcl: 1

<speechles> .tcl set rname [encoding convertfrom utf-8 "bla bla bla bla bla bla bla bla bla bla bla ¤ bla bla bla bla bla bla bla bla"]
<bot> Tcl: bla bla bla bla bla bla bla bla bla bla bla ¤ bla bla bla bla bla bla bla bla

<speechles> .tcl if {[regexp {\xa4} [encoding convertfrom utf-8 $rname]] == 1 || [string length $rname] > 45} { set d "works" } { set d "fails" }
<bot> Tcl: works

Code: Select all

if {[regexp {\xa4} [encoding convertfrom utf-8 $rname]] == 1 || [string length $rname] > 45} {..}
Post Reply