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.

Making an "caps" proc

Old posts that have not been replied to for several years.
Locked
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Making an "caps" proc

Post by metroid »

I was wondering if anyone has a clue about making a small "caps" proc, This proc would simply convert lowercase text into big text and the other way around aswell.
[caps moo]
<bot> MOO
[caps MOO]
<bot> moo
Thanks if any of you could be bored enough to make it :P
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Code: Select all

proc caps { text } {
  return [string toupper $text] ;# [caps moo] -> MOO
}

proc caps { text } {
  return [string tolower $text] ;# [caps MOO] -> moo
}
Now you have to figure out how to detect that string is lower or upper case.
Que?
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

I think that is what Metroid was asking. How to detect the case not how to change the case :wink:
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Actually, Both :)

It has to detect that it's uppercase and change it to lowercase and change it accordingly and the other way around aswell
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Code: Select all

if { ![string is upper $text } {
    return [string toupper $text]
} else { 
    return [string tolower $text]
}
not sure about this one heres what i would try.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Yeah, this will work :)
Que?
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Well, it seems it doesn't work exactly right

Code: Select all

[12:35:23] <M> Q caps "moo dss sss"
[12:35:26] <Q13> [TCL_OK 0.029ms] MOO DSS SSS
[12:35:36] <M> Q caps "MOO DSS SSS"
[12:35:39] <Q13> [TCL_OK 0.027ms] MOO DSS SSS
[12:35:40] <M> Q caps "MOO Dss SSS"
[12:35:43] <Q13> [TCL_OK 0.028ms] MOO DSS SSS

Code: Select all

proc caps { arguments } {
if {![string is upper $arguments]} {
	return [string toupper $arguments]
   } else {
   	return [string tolower $arguments]
  	}
   }
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

i think the only way to do this is split the $text up and change each characters case. loop through foreach $char maybe use a switch statement on it.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

MeTroiD wrote:Well, it seems it doesn't work exactly right
Space is not considered an uppercase character by 'string is upper'. How about something like this?

Code: Select all

proc invertCase str {
	string map {a A A a b B B b c C C c d D D d e E E e f F F f g G G g h H H h i I I i j J J j k K K k l L L l m M M m n N N n o O O o p P P p q Q Q q r R R r s S S s t T T t u U U u v V V v w W W w x X X x y Y Y y z Z Z z} $str
}
Have you ever read "The Manual"?
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Thanks user, that did exactly what i needed :)
Locked