String literals in MAXScript are one or more characters enclosed in double quotes:
"3ds Max" "August 4th, 1997"
String literals can contain any character except another plain double quote. You can include a double quote in a string literal, as well as some useful control characters, by using a "\" (backslash) escape character sequence.
The valid escape sequences are:
ESCAPE SEQUENCE | MEANING |
---|---|
\" |
a double quote character |
\n |
a newline character |
\r |
a carriage return character |
\t |
a TAB character |
\* |
an asterisk character |
\? |
a question mark character |
\\ |
a single "" character |
\% |
a percent character |
\x{d} |
a hexadecimal character |
EXAMPLE:
print "foo should be quoted like this: \"foo\" and a new line: \n"
would output:
"foo should be quoted like this: "foo" and a new line: "
A "\" character that does not preface one of the specified characters is left as a single backslash.
You can break a string literal into several lines and the line breaks will stay in the string.
FOR EXAMPLE:
"Twas brillig and the slithy tobes did gyre and gimbol in the wabe or something like that..."
Non-Printing Characters in Strings
You can specify non-printing characters in string literals using the \x hexadecimal escape sequence convention from C/C++. The form is:
\x{<hex_digit>}+ -- <hex_digit> is a hexadecimal digit (0-9,a-f)
EXAMPLE:
str = "Copyright \xa9 1997, FrabWorks, Inc"
would insert a copyright sign ©. Hexadecimal
a9
is the code for that symbol.
Running the following script displays in Listener the characters associated with each hexadecimal code:
EXAMPLE:
char= "0123456789abcdef" for i=1 to char.count do for j=1 to char.count do ( s=execute("\"\\x"+char[i]+char[j]+"\"") format "%% %\n" char[i] char[j] s )
File Path Name Strings
File path name strings use the backslash character to separate a parent directory from its sub-directory. The backslash is used as an escape character, therefore file path names specified in a string should use the escape character sequence for a single "\" character, i.e., "\", or specify the string as verbatim using the @ character introduced in 3ds Max 2008 (see further on this page)
AN EXAMPLE IS:
scene_path = "g:\\3dsmax25\\scenes" -- specifies file path g:\3dsmax25\scenes
For strings that are used as file names or paths, the "/" character can be used instead of the "\". MAXScript internally interprets the "/" character as a "\" character when used in a file path name string.
AN EXAMPLE IS:
scene_path = "g:/3dsmax25/scenes" -- specifies file path g:\3dsmax25\scenes
Verbatim String Literals
Verbatim string literals added to MAXScript in 3ds Max 2008 are prefixed by the '@' character and are NOT expanded even if containing backslash escape character sequences like '\t', '\n' or '\r'.
The syntax is
@"{<character>}+"
FOR EXAMPLE,
--the following verbatim string remains unchanged after evaluation: thePath = @"g:\temp\newfolder\render"
"g:\temp\newfolder\render"
--while the following results in a --scrambled string with tabs and new lines: thePath = "g:\temp\newfolder\render"
"g: emp ewfolder ender"