String
and char datatypes in PowerBuilder
General information
There is no explicit char literal type.
String literals convert to type char using the following
rules:
-
When a string literal is assigned to a char variable, the
first character of the string literal is assigned to the variable.
For example:1char c = "xyz"results in the character x being assigned to the char variable
c. -
Special characters (such as newline, formfeed, octal, hex, and
so on) can be assigned to char variables using string conversion,
such as:1char c = "~n"String variables assigned to char variables also convert using
these rules. A char variable assigned to a string variable results
in a one-character string.
Assigning strings to char
arrays
As with other datatypes, you can use arrays of chars. Assigning
strings to char arrays follows these rules:
-
If the char array is unbounded (defined as a variable-size
array), the contents of the string are copied directly into the char
array. -
If the char array is bounded and its length is less than or
equal to the length of the string, the string is truncated in the
array. -
If the char array is bounded and its length is greater than
the length of the string, the entire string is copied into the array
along with its zero terminator. Remaining characters in the array
are undetermined.
Assigning char arrays to
strings
When a char array is assigned to a string variable, the contents
of the array are copied into the string up to a zero terminator, if
found, in the char array.
Using both strings and chars in an
expression
Expressions using both strings and char arrays promote the chars
to strings before evaluation. For example, the following promotes the
contents of c to a string before comparison with the string “x”:
|
1 2 3 |
char c . . . if (c = "x") then |
Using chars in PowerScript
functions
All PowerScript functions that take strings also take chars and
char arrays, subject to the conversion rules described above.