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.

How to acquire the number of characters minus color codes

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
droolin
Halfop
Posts: 64
Joined: Thu Jul 24, 2003 9:07 pm
Contact:

How to acquire the number of characters minus color codes

Post by droolin »

Is there a way to count the number of characters in a string minus the hex codes for colors?
"\0034,1\xb0\xbaO\xa7\0030 ~ ~ ~ ~ ~ $botnick command help ~ ~ ~ ~ ~ "
If I do a string length on that, that returns the total count of characters including the hex values and such. Is there any way to only only get a length of printable characters including the subst value of $botnick.

drool
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Of course there's a way, strip off the stuff you don't want with either regsub or the stripcodes commands then use string length
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

If $text is "\0034,1\xb0\xbaO\xa7\0030 ~ ~ ~ ~ ~ $botnick command help ~ ~ ~ ~ ~"

then:

Code: Select all

#In eggdrop 1.6.17 and later, you can use:
set text [stripcodes bcruag $text]

#If you want to count spaces as characters
set textlen [string length $text]

#If you don't want to count spaces as characters
set textlen [string length [string map {" " ""} $text]]
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Post Reply