| «‹ 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 Functions |
分類: Programming Language |
High-level Programming Language (Pascal)
String Functions
- length (<InStr>)
- return the length of a <InStr> (i.e. the number of characters in the string)
- for example,
L := length ('computer studies'); {assign a value of 16 to L}
L := length (''); {assign a value of 0 to L}
L := length (' '); {assign a value of 1 to L}
- Concatenation
- is a process of joining strings together to form a longer string
- strings can be concatenated using the function concat or the concatenation operator (+)
- for example,
String1 := 'Pascal';
String2 :='Programming';
CombineString := concat (String1, String2);
{or CombineString := String1 + String2;}
writeln (CombineString); {the output is PascalProgramming}
- copy (<InStr>,<Start>,<Size>)
- returns a substring with the specified <Size> from the <InStr>,
- beginning at position <Start>
- for example,
copy ('A programming course', 3, 11); {returns the value programming}
- if <Start> is larger than the length of the <InStr>, an empty string (i.e. null string) is returned
- if <Size> goes beyond the end of the <InStr>, whatever is present is copied and returned
Ordering functions
- ord (<Character>)
- returns the ASCII value of a <Character>
- for example,
|
Character
|
ord (Character)
|
|
'A'
|
65
|
|
'Z'
|
90
|
|
' ' {a space}
|
32
|
|
'2'
|
50
|
|
'9'
|
57
|
|
'' {Null string}
|
0
|
- chr (<Code>)
- where <Code> is a non-negative integer
- the inverse of the ord function
- returns the ASCII character associated with <Code>
- for example,
|
Code
|
chr (Code)
|
|
49
|
'1'
|
|
50
|
'2'
|
|
65
|
'A'
|
|
66
|
'B'
|
|
97
|
'a'
|
|
|