| «‹ July 2026 ›» | | S | M | T | W | T | F | S | | | | 1 | 2 | 3 | 4 | | 5 | 6 | 7 | 8 | 9 | 10 | 11 | | 12 | 13 | 14 | 15 | 16 | 17 | 18 | | 19 | 20 | 21 | 22 | 23 | 24 | 25 | | 26 | 27 | 28 | 29 | 30 | 31 | |
|
2009 年 9 月 11 日 星期五  |
| String Operation |
分類: Programming Language |
High-level Programming Language (Pascal)
Basic Operations on Strings
Assignment
- for example,
Name := 'Chan Tai Man';
Class := 'F4A';
Address := 'Rm 5, 20 / F, 108 School Road, Hong Kong.';
- the value being assigned may be a string shorter than the declared length of the variable, the lengths of Name and Address are 12 and 40 characters respectively
- if the length of the value being assigned is longer than the declared length of the variable, the value is truncated to the size of the variable, the actual value of Class is 'F4'
Input/Output
for example,
'DAVID' is less than 'David', because 'A' is less than 'a'
- leading and trailing blank spaces are significant in string comparisons
for example,
'computer' is less than 'computer' because the blank space comes before the letter 'c' in the ASCII table
'computer' is greater than the string 'computer' because the former one is longer
Initialization of string variable
- uninitialized string may contain unpredictable value
- Name := '';
{initialize a string variable Name with a null string, there is no space between the quotation marks}
- Null string (empty string) is a string with zero character
Name := ' '; {initialize a string variable Name with one space}
|
|