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.

non case-sensitive arrays?

Old posts that have not been replied to for several years.
Locked
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

non case-sensitive arrays?

Post by arcane »

hi
does anyone know an easy way of making arrays non case-sensitive? means, array(#chan) should be the same as array(#ChAn).

thats what i use in my script:
1. if { [info exists array($chan)] } { ...
2. if { $array($chan) == "value" } { ...
3. set array(#chan) "value"
4. [llength $array($chan)]
5. [lsearch $array($chan) ...

3. is set by users, so i dont know whether they use #chan or #ChaN or whatever else.
users can set values for each channel like "set flags(#mychan) o" but they dont have to. so flags(#mychan) may exist or may not exist.

so all these commands should see array(#chan) as array(#Chan) and so on... i found no easy way of switching off case-sensitivity, but perhaps one of you knows a way. hope this post is not too confusing... :-?
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Code: Select all

proc array_names_to_lowercase {array} {
  upvar 1 $array a
  set b [array get a]
  unset a
  foreach {n v} $b {set a([string tolower $n]) $v}
}
Or, if keeping the screwed up case is importtant, you could do an lsearch in a lowercase version of [array names the_array] and then fetch [lindex [array names the_array] index_returned_by_lsearch]

Or how about asking them not to use uppercase letters? :P
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

alright, thx
user wrote:Or how about asking them not to use uppercase letters? :P
this wont work - theres always some idiot :P whats more, some of the $chans are taken from eggdrops chanlist. but doesnt matter. :D
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
Locked