Discussion:
HELP! I need to tell if a word ends in 's'
(too old to reply)
Andrew Mueller
2003-07-15 12:40:24 UTC
Permalink
I need to check a string for a trailing 's' so I
can print a correctly formatted message to the room.

I've tried different sscanf() combos, but can't get
the syntax right.

This HAS to be easy, and I'm ashamed that I can't
figure it out on my own. Thanks in advance!!

-Andy M
dhmud.com 3000
Lars Duening
2003-07-15 16:31:07 UTC
Permalink
Post by Andrew Mueller
I need to check a string for a trailing 's' so I
can print a correctly formatted message to the room.
I've tried different sscanf() combos, but can't get
the syntax right.
Well, you could explode() the string by spaces, and then use simple
indexing to check every word in the result if the last character is a
's'.

However, I am curious as to why you want to do that in the first place,
as sprintf() and terminal_colour() already provide formatting
capabilities.
Lars Duening
2003-07-16 05:59:10 UTC
Permalink
I'm fixing our lighted armor support. Right now, if you remove a pair
of lighted boots, you get a message "The boots stops glowing." instead
of "The boots stop glowing."
I need to test the this_object()->query_name(), if it's 'boots', I'll
print "The boots stop glowing.", if it's 'helmet', I'll print "The
helmet stops glowing."
Ah, that makes sense now. In LDMud syntax:

verb = "stop";
if (query_name()[<1] != 's')
verb = "stops";
write("The "+query_name()+" "+verb+" glowing.\n");

For other drivers you probably have to replace 'query_name()[<1]' with
query_name()[ strlen(query_name())-1 ]'.

Another approach would be to give objects a query_is_plural() predicate
which returns true for boots, gloves, etc, false for others, and use
that.
Andrew Mueller
2003-07-16 12:56:41 UTC
Permalink
Post by Lars Duening
I'm fixing our lighted armor support. Right now, if you remove a pair
of lighted boots, you get a message "The boots stops glowing." instead
of "The boots stop glowing."
I need to test the this_object()->query_name(), if it's 'boots', I'll
print "The boots stop glowing.", if it's 'helmet', I'll print "The
helmet stops glowing."
verb = "stop";
if (query_name()[<1] != 's')
verb = "stops";
write("The "+query_name()+" "+verb+" glowing.\n");
For other drivers you probably have to replace 'query_name()[<1]' with
query_name()[ strlen(query_name())-1 ]'.
Another approach would be to give objects a query_is_plural() predicate
which returns true for boots, gloves, etc, false for others, and use
that.
It works like a charm, thanks!!

-Andy M

Loading...