Pascal Common functions

Source: Internet
Author: User

  

Inc (I) make i:=i+1;

Inc (I,B) makes i:=i+b;

Dec (i) makes i:=i-1;

Dec (i,b) makes i:=i-b;

ABS (x) to find the absolute value of x: ABS (-3) =3

Chr (x) to find the character that corresponds to the number x. Example: CHR = ' a ' chr (+) = ' A ' chr (48) = ' 0 '

Ord (x) to find the number corresponding to the character X. Example: Ord (' a ') =65 ord (' a ') =97 in addition: Ord (false) =0 Ord (True) =1

SQR (x) asks for the square of X. Example: Sqr (4) =16

sqrt (x) asks for the root of X. Example: sqrt (16) =4

Round (x) Rounding example of x: Round (4.5) =5

Trunc (x) to find an integer part of x: Trunc (5.6) The =5 result is an integer type

int (x) to find an integer part of x int (5.6) =5.0 result is a real type

Frac (x) to find a small part of X frac (5.6) =0.6

Pred (x) to find the leading pred of X (' B ') = ' A ' pred (5) =4 pred (True) =false

SUCC (x) for the subsequent succ of X (' B ') = ' C ' succ (5) =6 succ (false) =true

Odd (x) determines whether x is an odd number. If the value is true, the inverse value is false. Odd (2) =false odd (5) =true

Power (A,n) asks for the N Power (2,3) of a =8 { can only be used when you open the math library }

Random number between 0~1 (cannot be taken to 1)

Randomize the seed function of a random number, the function is placed at the top of each set of random numbers.

Fillchar (A,size (a), 0) array initialization, that is, the value of array A is all set to 0 {The Boolean variable is also possible}

SHR:X SHR n convert x to binary and move N to the right, equivalent to dividing x by 2n

Shl:x SHL n turns x into binary and shifts the n position to the left, which is equivalent to multiplying x by 2n

1. The connection operation Concat (S1,S2,S3...SN) is equivalent to S1+S2+S3+...+SN.

Example: concat (' One ', ' aa ') = ' 11AA ';

2. Ask for a substring. Copy (s,i,l) intercepts the substring of length L after the beginning of the first character from the string s.

Example: Copy (' Abdag ', 2,3) = ' BDA '

3. Delete the substring. Procedure Delete (s,i,l) removes a substring of l after the start of the first character from the string s.

Example: s:= ' ABCDE ';d elete (s,2,3); results s:= ' AE '

4. Insert a substring. Procedure Insert (S1,s2,i) inserts the S1 into the first position of the S2

Example: S:=abc;insert (' n ', s,2); result s:= ' A12BC '

5. String length (s) Example: Length (' 12abc ') =5

6. Search for the location of the substring POS (S1,S2) If S1 is a substring of S2, returns the position of the first character of S1 in S2, or 0 if it is not a substring.

Example: POS (' ab ', ' 12ABCD ') =3

7. Uppercase conversions for characters. UpCase (CH) to find the uppercase body of the character Ch.

Example: UpCase (' a ') = ' a '

8. The numeric value is converted to a string. The process str (X,S) turns the value x into several strings of S.

Example: Str (12345,s); Results s= ' 12345 '

9. Number of strings converted to numeric values. The process Val (s,x,i) converts several strings of s into numerical X, and if successful it is i=0, unsuccessful then I is an ordinal of an invalid character

Example: Val (' 1234 ', x,i); result x:=1234

①: The pred (x) function value is x-l, for example:

Pred (6) =5 pred (-21) =-22

② successor function: The value of the SUCC (x) function is x+l, for example:

SUCC (L5) =16 SUCC (-114) = 113

③ Absolute Value function: the Abs (x) function values are ︱x︱, for example:

ABS ( -119) =119 ABS (101) =101

④ Square Function: The value of the SQR (x) function is X2, for example:

Sqr ( -5) =,25 sqr (l0) = 100

The result of the above four functions is still an integer number.

⑤ odd function: Odd (x), the result of the function is a Boolean type. When x is odd, the function value is true, and when X is even, the function value is false. For example:

Odd = True odd (+) = False

⑥ character function: Chr (X), the function value is the ASCII character of the ordinal, which is a character type. For example:

CHR = ' A ' chr (32) = '

Absolute function abs (x): The value of the function is the absolute number of X

Square function Sqr (x): The function value is the square of X

Decimal function Frac (x): Fractional part of the function value X

integer function int (x): function value is an integer part of X

sqrt (x) of the square root function: The value of the function is the square root of X

Stochastic function Random: When there is no argument, the function value takes a random number between (0,1), and when there is an independent variable and is a Word type, the function value takes a random integer between (0, the argument).

successor function SUCC (CH): For example, SUCC (' 8 ') = ' 9 ' Succ (' E ') = ' F '

The SUCC function has no meaning for the last character of the character set.

Pre-trend function Pred (CH): For example, Pred (' 7 ') = ' 6 ' Pred (' B ') = ' A '

ordinal function ord (CH):: Gives the ordinal of the character ch in the ASCII character set, the result is an integer type.

Ord (B) For example: Ord (False) =0 Ord (True) =1

Pascal Common functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.