A character string, which may also be called a string constant or string literal, contains a sequence of characters or escape sequences enclosed in double quotation mark symbols. Character strings represent names, labels, titles, and messages. The meaning of each character value depends on the code page (character set) defined for the resource script file.
A string constant has the form:
┌───────────────────┐ >───"─┴┬──character──────┬┴─"───────────────────────────────────────> └─escape_sequence─┘
Where:
character
A hexadecimal escape sequence contains an character x followed by one or more hexadecimal digits (0-9, A-F, a-f). An octal escape sequence contains one or more octal digits (0-7). The value of the hexadecimal or octal number specifies the value of the desired character.
An escape sequence has the form:
>───\──┬─escape_sequence_character─┬───────────────────────────────>< ├─octal_digits──────────────┤ └─x─hexadecimal_digits──────┘
┌──────────────────────────────┬──────────────────────────────┐ │Escape sequence │Character Represented │ ├──────────────────────────────┼──────────────────────────────┤ │\a │Alert (bell) │ ├──────────────────────────────┼──────────────────────────────┤ │\b │Backspace │ ├──────────────────────────────┼──────────────────────────────┤ │\f │Form feed (new page) │ ├──────────────────────────────┼──────────────────────────────┤ │\n │Newline │ ├──────────────────────────────┼──────────────────────────────┤ │\nnn │Octal character │ ├──────────────────────────────┼──────────────────────────────┤ │\xdd │Hexadecimal character │ ├──────────────────────────────┼──────────────────────────────┤ │\r │Carriage return │ ├──────────────────────────────┼──────────────────────────────┤ │\t │Horizontal tab │ ├──────────────────────────────┼──────────────────────────────┤ │\v │Vertical tab │ ├──────────────────────────────┼──────────────────────────────┤ │\' │Single quotation mark │ ├──────────────────────────────┼──────────────────────────────┤ │\" │Double quotation mark │ ├──────────────────────────────┼──────────────────────────────┤ │\? │Question mark │ ├──────────────────────────────┼──────────────────────────────┤ │\\ │Backslash │ └──────────────────────────────┴──────────────────────────────┘
When you want the backslash to represent itself (rather than the beginning of an escape sequence), you must use a \\ (two backslashes) escape sequence.
If two consecutive strings appear on the same source line without any space between these two strings, the strings will be merged with an embedded quote.
/* Source Line 1 */ "String 1""String 2"
Here two strings are specified on the same line with no space between the strings. These strings will be merged as - String 1"String 2. Here the ending double quote of first string and begin double quote of second string creates the effect of embedded double quotes inside the merged string. These consecutive double quote characters will be translated as a single double quote character. This is the same representation as shown below:
/* Source Line 1 */ "String 1\"String 2"
Here an escape sequence \" is used to include double quote character inside the string. This is the recommended representation to include a double quote character inside the string.
If one or more consecutive strings are separated by one or more spaces (the end of source line is considered as space also), then strings will be concatenated to produce a single string. See the following example:
/* Source Line 1 */ "String 3:" "String 4", /* Source Line 2 */ "String 5:" /* Source Line 3 */ "String 6"
The two strings "String 3:" and "String 4" specified on source line 1 are on the same line separated with a single blank. These two strings will be concatenated as shown below:
String 3:String 4
The two strings "String 5:" and "String 6" specified on source lines 2 and 3 are on different source lines. These two strings will be concatenated the same way as with strings specified on source line 1.
String 5:String 6
Note that the comma had been specified after the "String 4" in source line 1 to stop the concatenation of strings on source lines 2 and 3. If that comma had not been specified, then all the strings on source lines 1, 2, and 3 would have been merged as shown in the following example:
String 3:String4String5:String6
If the string has no ending double quote mark at the end of the source line, then the physical end of source line will generate a newline character as part of the string data.
"This string on source line 1 is continued on source line 2"
In the above example, the newline character (hex 0A) will be inserted after character 1. This representation is equivalent to the following example.
"This string on source line 1\nis continued on source line 2"
Here the escape sequence \n is used to generate newline character (hex 0A) between two strings.
"String on Line 1 String on Line 2"
In the above example, the second string on line 2 is specified with two leading spaces. These leading spaces will be part of the string data. If you do not want any leading space on the strings that span next lines, then start the strings in column 1 on the next lines. This representation is equivalent to the following example.
"String on Line 1\n String on Line 2" You can use an another approach like the following example: "String on Line 1\n" " String on Line 2"
This approach is more readable. Here the concatenation operation will be performed on both strings without worry about the leading spaces before the string " String on Line 2". Leading spaces are provided inside the second string so you can place second string on the next line at the indented place. See the following STRINGTABLE statement example.
STRINGTABLE { 1, "The data on disk will be erased\n" "Are you sure (Y/N) \?" }
You can use the escape sequence \n to represent a new-line character as part of the string. You can use the escape \\ to represent a backslash character as part of the string. You can use the escape \" to present the double quotation mark symbol as part of the string. You can include any ASCII character in a character string by specifying \xdd, where dd is the hexadecimal representation of an ASCII character. An error message is issued if an escape sequence is not recognized.
In addition, when character strings are used as resource identifiers additional rules apply:
When the Resource Compiler is compiling a script file and encounters more than one resource of the same type having the same string ID, it will generate an error message and stop compiling the file. When the Resource Compiler is binding a .RES file and encounters more than one resource of the same type with the same string ID, it will generate a warning message and ignore the second resource identifier; only the first resource having the duplicated identifier will be bound to the file.