Strings

Mel has a very nice string variable type.  The syntax for working with them, however,
may be a bit confusing at first.  I hope to clear some of that up here.
Lets start with string concatenation, which refers to combining multiple strings into one.

{ string $aString = "This string is"; string $other = " awesome"; string $end = "!"; string $all = $aString + $other + $end; print $all; }
Wow. By the way, you don't need to combine them all into a new variable before printing. You could also use: print ($aString + $other + $end); and skip the creation of the $all variable.
You can concatenate string variables with text strings as well: { string $this = "This string is not very cool"; print ($this + " but this one is."); } This can be very useful in scripts where you need to work with attributes on objects whose names you don't know before the script is run. This example also uses arrays and return values. { string $sphere[] = `sphere`; setAttr ($sphere[0] + ".scaleY") 13; print ($sphere[0] + ".scaleY" + "\n"); } Special Characters You've probably noticed the use of "\n" several times in these examples. That is an example of the escape character being used to create a special character, in this case the newline character. It tells maya to go down to the next line, when it's printing that string. The \ character is special. It is the escape character. It tells maya to use an alternate interpretation of whatever character follows it. Instead of printing the letter n, \n tells maya to create a new line. Suppose you need to have quotation marks in a string. Doing this: { string $this = ""quotes""; print $this; } will result in a syntax error. Maya reads those first two quotes as beginning and ending a string, and doesn't know what to do with the rest. All you need to do is escape those internal quotes, and it will work fine. { string $this = "\"quotes\""; print $this; } If you want to have the escape character inside a string you need to escape it like so: { string $escaping = "\\escape character\\"; print $escaping; } some other useful escape sequences are: \t to tab in \r carriage return, very similar to newline but with an extra space This may all seem somewhat grammatical and not very useful, but it becomes crucial later on when you need to assemble commands at runtime.