[Pascal – TUT] Posts 6: String

You. Character (tank)

1. Concept
Char type used to represent the letters of the alphabet, digits and special characters.
To perform the information you need to arrange the characters in a table, It is usually arranged in ASCII. ASCII there 256 characters, Each character is assigned codes from 0 to 255.

2. Some related content
– WORD(ch) Results of the ASCII code for the character ch.;
– CHR(x) the result is the character code corresponding to x.
– UPCA(ch) for uppercase letters of ch.

* In Pascal does not have a function to convert uppercase letter lowercase letters, however we can build by performing the following: chr(word(ch)+32).{Change the uppercase letter lowercase letters ch}

II. String (string)

String data type is structured to handle the string. It has many similar but different array is the number of array elements is fixed while the strings are mutable.

[qads]

1. Declare
How to 1: Declaring indirect

type <tên kiểu>=string[độ dài tối đa];
var <tên biến>:<tên kiểu>;

How to 2: Declaring directly

var <tên biến>:string[độ dài tối đa];

In that: The maximum length of a string is 255. I can without burning [maximum length] Meanwhile the default length of the string is 255 characters.

2. Get access each element of the sequence
To access each element of the chain do the same as for arrays 1 evening.

3. The structure of the string variable
Suppose we have a string variable is the variable s. In memory it occupies the number of bytes in the maximum number of characters plus a first byte at location s[0]. with[0] ASCII characters rather than its actual length of the string by. With this we can count the actual length of the string by using Ord(with[0])

4. Enter the string output
We use the Write or writeln statement to output the string, readln command to read or enter the string.

5. Operations, jaw, further testing on chain
the. Assignments
String in single quotes (‘ '). :=

b. Summation: +

c. Comparing strings
When comparing two strings, the characters are compared in pairs left to right according to an ASCII.

d. Ham length(st)
Result is integer only real length of chain st.

and. Copy Function(st,Post,n)
Returns a string extracted from the string st, copy n characters from position pos.

g. Concat function(ST1, ST2, ST3,…,stn) connection strings

h. Ham Pos(st1, st)
Result is a first position in the string st1 st. If not found, the function returns the result is 0.

in. The function str(with:n:m,st)
The function str(with:n:m,st) Change the chain's number and assigned to st.

to. Try to Val(st,with,code)
Refresh the number and assign St S, Code is a variable of type Integer. If true, the Code Change the value 0, if not wrong against St perform integer or real numbers, the Code by the value of the wrong character position in the string St.

the. Procedures DELETE(st, post, in): num delete characters in the string from position pos st
Example: st = "abcVietsource.net '
Delete(st,1,3) st is the time for the 'Vietsource.net'

m. Procedures INSERT(obj, st, post): Procedures for results by inserting strings called Obj vaoxau st at position pos, pos characters will be moved behind the back of the string vephia obj.
Example: obj:= ‘source ‘
st:= 'Viet.net';
INSERT(obj,st,5) then st = 'Vietsource.net';


Original article: vietsource.net