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.

need help creating an autovoice

Old posts that have not been replied to for several years.
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

i saw nothing pertaning to a single word,
what examples i did see pertained to
a sentence on ALL of the commands

why would the paramaters be different
for string range than string trimright?
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Dedan wrote:i saw nothing pertaning to a single word,
what examples i did see pertained to
a sentence on ALL of the commands
What do you mean? The string commands work with what you feed them...in general a string of chars...there are no words :P

Dedan wrote:why would the paramaters be different
for string range than string trimright?
string trimright doesn't deal with indexes, it trims of the chars specified (read the manual)
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

Code: Select all

set word "eggdrop" 

proc get:stuff { stuff } { 
  global word
  set first3letters [string range $word first 2]
  # returns egg
  set firstletter [string range $word first 0]
  # returns e
  if {[regexp {[0-9]} $firstletter]} {return "letter is a number silly"}

} 

I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

replace "first" with "0" and use 'string index $word 0' to fetch the single char...no need to use range to fetch something that aint a range :)
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

thanks 8)
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

user wrote:regexp SUCKS :P (so slow compared to most string commands that perform such tasks...it's only needed for really complex patterns that would require lots of other commands)

Here's an example (matching a number as the first char in a string):
% set a 0abcdefghijklmnopqrstuvwxyz
0abcdefghijklmnopqrstuvwxyz
% time [list regexp {[0-9]+.*} $a] 100000
10 microseconds per iteration
% time [list string match {[0-9]*} $a] 100000
2 microseconds per iteration
For the record, it might help a little bit if you used the correct regexp ;)

Code: Select all

regexp {^[0-9]} $a
Instead of having it search the string anywhere for a number ;x

Also, I can not stress enough the importance of writing compatible code for various TCL versions, and Eggdrop versions... While string match is faster, it does not support regular expression matching in all TCL versions. Keeping this in perspective, 5-6 MICROseconds are inconsequential, for the price of retaining backwards compatibility.
:)
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

strikelight wrote:For the record, it might help a little bit if you used the correct regexp ;)
Yeah :oops: (It wouldn't matter much to the speed difference though)
strikelight wrote:Also, I can not stress enough the importance of writing compatible code for various TCL versions, and Eggdrop versions... While string match is faster, it does not support regular expression matching in all TCL versions. Keeping this in perspective, 5-6 MICROseconds are inconsequential, for the price of retaining backwards compatibility.
:)
What do you mean? You're coding for some version < 7.5?
And for the record, microseconds matter when you execute stuff millions of times :)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

user wrote:regexp SUCKS :P (so slow compared to most string commands that perform such tasks...it's only needed for really complex patterns that would require lots of other commands)

Here's an example (matching a number as the first char in a string):
% set a 0abcdefghijklmnopqrstuvwxyz
0abcdefghijklmnopqrstuvwxyz
% time [list regexp {[0-9]+.*} $a] 100000
10 microseconds per iteration
% time [list string match {[0-9]*} $a] 100000
2 microseconds per iteration
ok, do these two examples (regexp and string) do exactly the same thing ?
like I can convert any regexp to a string on the same concept ?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Sir_Fz wrote:ok, do these two examples (regexp and string) do exactly the same thing ? like I can convert any regexp to a string on the same concept ?
No. Use {^[0-9]} in the regexp to match the same thing as {[0-9]*} using string match.

Most regexp rules CAN'T be translated into string match masks, but when they can and become alot more efficient, they should be IMO. (Read the manual to find out what you can and can't)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

which manual ?
Locked