What does string mean in pascal and how to use it

Updated on educate 2024-03-27
3 answers
  1. Anonymous users2024-02-07

    1.Strings are used to store entire batches of character data. Strings are commonly used in programming to store characterized numeric data.

    For example, when performing high-precision operations, operands and calculation results are stored. Strings can be treated as special arrays of strings. Of course, it also has its own characteristics.

    Here's the format of the string definition:

    vars:string;

    s1:string[15];

    If the length of a string is not specified, the space is allocated according to the maximum length of the type (255 characters), and the maximum available length is 255. If a specific value (between 1 and 255) is given in parentheses, the space is allocated according to the size of the value. When used, the maximum usable length is this value.

    2.Input, output of strings:

    The string type can be input and output as an array, or directly input and output: readln(s); writeln(s);When multiple strings are entered, carriage return is used as the separator between data; Each readln statement can only read one string.

    3.Operations on strings (brought by pascal):

    length(s)

    Function. Find the length of the string s.

    The return value is integer.

    s:='123456789';

    l:=length(s);

    copy(s,w,k)

    Function. Copy the k bits starting from w in s.

    The return value is a character.

    s:='123456789';

    s1:=copy(s,3,5);

    val(s,k,code)

    Process. Convert the string s to a numeric value and store it in k; code is an error ** (generally do not consider using val(s,k)).

    s:='1234';

    val(s,k);

    str(i,s)

    Process. Convert the value i to the string s

    i:=1234;

    str(i,s);

    delete(s,w,k)

    Process. Remove k characters starting from the wth bit in s.

    s:=honest

    abelincoln';

    delete(s,8,4);

    Operator. Concatenate the two strings.

    s1:='1234';s2:='5678';

    s:=s1+s2;

  2. Anonymous users2024-02-06

    program

    ex8_5;

    vars1,s,o:string;

    i:integer;

    beginwrite('the

    text:');

    readln(s1);

    write('find:');readln(s);

    write('replace:');readln(o);

    i:=pos(s,s1);

    whilei<>0

    dobegin

    delete(s1,i,length(s));

    insert(o,s1,i);

    i:=pos(s,s1);

    end;writeln(s1);

    readln;

    end.1. Definition of String.

    A string is an infinite sequence of characters, defined by the string type:

    typeString type identifier》=string[n];

    var string variable: string type identifier;

    Wherein: n is the defined string length, which must be a natural integer between 0 255, the actual length of the string is stored in unit 0, which is automatically provided by the system when the program runs, and the characters of the string are stored in unit 1 n, if string[n] is written as string, the default n value is 255.

    For example: type

    man=string[8];

    line=string;

    varname:man;

    screenline:line;

    Another way to define a character type is to combine the variable definitions of the type description.

    For example: var

    name:string[8];

    screenline:string;

    In TurboPascal, characters in a string can be flexibly used by their corresponding subscripts.

    For example: var

    name:string;

    beginreadln(name);

    fori:=1

    toord(name[0])

    dowriteln(name[i]);

    end.

  3. Anonymous users2024-02-05

    The Turbo Pascal language provides the following standard functions in which the argument is a character, where CHR is a character.

    Successor function succ(ch): e.g., succ('8')='9’ succ (’e’)='f’

    For the last character of the character set, the succ function is meaningless.

    Pred (ch): e.g., pred ('7')='6’ pred (’b’)=' a’

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

    Note: ord ('7')<7, the correct one is: ord ('7')=ord('0')+7=48+7=55

    If ch is a numeric character, then ord (ch) - ord ('0') is the numeric value of the numeric character, for example: ord ('7')-ord('0')=7

    The character function chr (i) described earlier is the inverse of ord (ch), e.g. chr (55) = '7' chr (ord('a'))='a’

    4. Boolean type functions.

    The Turbo Pascal language provides Boolean functions, mainly several character functions.

    ord (b) e.g. ord (false)=0 ord (true)=1.

Related questions
9 answers2024-03-27

Of course, you can instantiate.

The final class cannot be inherited by other classes. >>>More

4 answers2024-03-27

I don't dare to be a noi master, but I have participated in noip. >>>More

15 answers2024-03-27

First, the bubbling method sorting.

for i:=1 to n-1 do >>>More

10 answers2024-03-27

Bergson divides time into two types.

One is the time of life. >>>More

8 answers2024-03-27

string excelname= excelfileurl();The path to return to excel. >>>More