Go to the first, previous, next, last section, table of contents.


Fun With String

Text is a Big Deal on interactive systems like muds: Text is what people type in, text is what gets displayed on their terminals, text is what the programs are composed of, text is used for people's names ... text is just all over!

For some reason, programmers insist on referring to text as "string". The logic of this escapes me, but the standards Muq follows do this too, so we'll do likewise.

MUF has a lot of words for doing things with strings.

Here are some examples:

Sticking two strings together:

Stack: 
"String1" "String2"
Stack: "String1" "String2"
join
Stack: "String1String2"

Sticking three strings together:

Stack: 
"String1" "String2" "String3"
Stack: "String1" "String2" "String3"
join
Stack: "String1" "String2String3"
join
Stack: "String1String2String3"

Sticking three strings together done all on one line:

Stack: 
"String1" "String2" "String3" join join
Stack: "String1String2String3"

Counting the number of characters in a string:

Stack: "String1String2String3"
length
Stack: 15

Converting between upper, lower, and mixed cases:

Stack:
"I love Lucy"
Stack: "I love Lucy"
stringUpcase
Stack: "I LOVE LUCY"
stringDowncase
Stack: "i love lucy"
stringMixedcase
Stack: "I love lucy"

(Notice that MUF is too stupid to capitalize "Lucy" when going to mixed case. It doesn't know anything about names. It does know about "I" and capitalizing the first word in a sentence, however, which isn't bad for such a simple-minded little program.)

Getting a substring from the middle of a string:

Stack:
"abcdef"
Stack: "abcde"
1 4 substring
Stack: "bcd"

'Substring' numbers letters starting from zero, so 'b' is letter number '1' in "abcdef". 'Substring' extracts letters until it gets to just before the second letter number given, which was '4' in this case. So in this case, it extracts characters number one, two, three: 'b', 'c', 'd'.

(This will probably seem a peculiar way of doing business to you, but turns out to be convenient when writing lots of programs to work with strings. For example, when extracting a sequence of adjacent substrings, the ending index for one string is the same as the starting index for the next string, which saves adding or subtracting one.)


Go to the first, previous, next, last section, table of contents.