The relational operators =, <>, <, >, <=, and >= all take string operands (see Relational operators). The + operator concatenates two strings.
Operator
|
Operation |
Operand types |
Result type |
Example |
|
+ |
concatenation |
string, packed string, character |
string
|
S + ‘.’ |
The following rules apply to string
concatenation.
· The operands for + can be strings, packed strings (packed arrays of
type Char), or characters. However, if one operand is of type WideChar,
the other operand must be a long string.
· The result of a + operation is compatible with any string type. However, if the operands are both short strings or characters, and their combined length is greater than 255, the result is truncated to the first 255 characters.
关系运算符=、<>、<、>、<=和>=都可以将串作为操作数进行运算(见关系运算符)。加号(+)以串为操作数时连接两个串。
运算符
|
操作 |
操作数类型 |
结果类型 |
范例 |
|
+ |
连接 |
串、压缩串、字符 |
串
|
S + ‘.’ |
下列规则适用于串的连接:
· 加号(+)运算符的操作数可以是串、压缩串(Char类型的压缩数组)或字符。然而,如果其中一个操作数是WideChar类型,那么另一个操作数必需是一个长串。
· 加号(+)运算符对串运算的结果,其类型与任意串类型兼容。然而,如果操作数都是短串或字符,而它们连接后的长度大于255,那么运算结果将只保留前255个字符,而将多余的部分截去。
编者注
加号(+)运算符对串的操作与其对数字的操作有很大差异。对于数字A、B和串S1、S2,表达式A + B与B + A是等价的,而表达式S1 + S2与S2 + S1不是等价的。例如,当S1为’Hello’、S2为’World’时,S1 + S2返回的值是’HelloWorld’,而S2 + S1返回的值是’WorldHello’。也就是说,当加号(+)作为串运算符时,操作数的位置顺序直接影响运算结果。