Welcome to the Builder Academy

Question Upper and lower case in echos

More
19 Jun 2013 03:16 #3163 by Parnassus
Is there a command to change the first letter of a variable in an echo from lower case to upper case or vice versa?

I figure the really ugly way is to strip off the first character and do if a then A and so on but there must be a better way. What about stripping the first letter, turning it to ascii and adding or subtracting 32 or whatever it takes and then changing it back? Or maybe (hopefully) there's a nice simple command that does it?

Please Log in or Create an account to join the conversation.

More
19 Jun 2013 05:36 #3164 by Vatiken
toupper()

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

More
20 Jun 2013 00:37 #3175 by Parnassus
Yes, that's it exactly! But can it be used in a trigger? Could you please describe to me how to use it? Is there a set involved?

For example, how would the echo of the variable word be changed to the echo Word?
%echo% toupper(%word%)

or maybe

set word toupper(%word%)
%echo% %word%

Please Log in or Create an account to join the conversation.

More
20 Jun 2013 02:14 #3177 by krell
Replied by krell on topic Upper and lower case in echos

Vatiken wrote: toupper()


Is that a built-in dg_script function? I've been grepping the source and the dg_script found in lib/worlds but all I can find is the C toupper(). Perhaps it's been recently added in the git repository?

Please Log in or Create an account to join the conversation.

More
20 Jun 2013 18:20 #3182 by Fizban
It's not a dg-command unless he just added which I doubt.

I'll have a working sample made shortly that is somewhat hack-ish, but much more concise than the method you mentioned in the opening post.

Please Log in or Create an account to join the conversation.

More
20 Jun 2013 18:32 - 20 Jun 2013 18:38 #3184 by Fizban
This is untested, but should work:
Code:
if %arg% set lower abcdefghijklmnopqrstuvwxyz set upper ABCDEFGHIJKLMNOPQRSTUVWXYZ if %cmd% == cap set firstletter %arg.charat(1)% if %lower.contains(%firstletter%)% set i 1 while %i% < 27 eval lettercheck %lower.charat(%i%)% if %lettercheck% == %firstletter% break end eval i %i% + 1 done set newfirst %upper.charat(%i%)% set length %arg.strlen% set ii 2 set word %newfirst% while %ii% <= %length% set word %word%%arg.charat(%ii%)% eval ii %ii% + 1 done else %echo% This argument doesn't begin with a lowercase letter. end end else %echo% You need to type 'cap' followed by another word for this script to work. end

29 lines is a bit longer than I'd like, but it's still much shorter than:
Code:
set firstletter %arg.charat(1)% if %firstletter% == a set newfirst A elseif %firstletter% == b set newfirst B ...

as that route would be close to 100 lines (it'd be 50+ before rebuilding the rest of the word which mine already has included in its 29 lines).
Last edit: 20 Jun 2013 18:38 by Fizban.
The following user(s) said Thank You: Parnassus

Please Log in or Create an account to join the conversation.

Time to create page: 0.193 seconds