Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


Lecture notes, cheat sheets
Free library / Directory / Lecture notes, cheat sheets

Computer science and information technology. Files (lecture notes)

Lecture notes, cheat sheets

Directory / Lecture notes, cheat sheets

Comments on the article Comments on the article

Table of contents (expand)

LECTURE #5. String data type

1. String type in Pascal

A sequence of characters of a certain length is called a string. Variables of string type are defined by specifying the name of the variable, the reserved word string, and optionally, but not necessarily, specifying the maximum size, i.e., the length of the string, in square brackets. If you do not set the maximum string size, then by default it will be 255, i.e. the string will consist of 255 characters.

Each element of a string can be referred to by its number. However, strings are input and output as a whole, not element by element, as is the case with arrays. The number of characters entered must not exceed that specified in the maximum string size, so if such an excess occurs, then the "extra" characters will be ignored.

2. Procedures and functions for string type variables

1. Function Copy(S: String; Index, Count: Integer): String;

Returns a substring of a string. S is an expression of type String.

Index and Count are integer type expressions. The function returns a string containing Count characters starting at the Index position. If Index is greater than the length of S, the function returns an empty string.

2. Procedure Delete(var S: String; Index, Count: Integer);

Removes a substring of characters of length Count from string S, starting at position Index. S is a variable of type String. Index and Count are integer type expressions. If Index is greater than the length of S, no characters are removed.

3. Procedure Insert(Source: String; var S: String; Index: Integer);

Concatenates a substring into a string, starting at a specified position. Source is an expression of type String. S is a variable of type String of any length. Index is an expression of integer type. Insert inserts Source into S, starting at position S[Index].

4. Function Length(S: String): Integer;

Returns the number of characters actually used in string S. Note that when using null-terminated strings, the number of characters is not necessarily equal to the number of bytes.

5. Function Pos(Substr: String; S: String): Integer;

Searches for a substring in a string. Pos looks for Substr within S and returns an integer value that is the index of the first character of Substr within S. If Substr is not found, Pos returns null.

3. Recordings

A record is a collection of a limited number of logically related components belonging to different types. The components of a record are called fields, each of which is identified by a name. A record field contains the name of the field, followed by a colon to indicate the type of the field. Record fields can be of any type allowed in Pascal, with the exception of the file type.

The description of a record in the Pascal language is carried out using the service word RECORD, followed by the description of the components of the record. The description of the entry ends with the service word END.

For example, a notebook contains last names, initials, and phone numbers, so it is convenient to represent a separate line in a notebook as the following entry:

type Row = Record

FIO: String[20];

TEL: String[7];

end;

var str: Row;

Record descriptions are also possible without using the type name, for example:

var str : Record

FIO : String[20];

TEL : String[7];

end;

Referencing a record as a whole is allowed only in assignment statements where record names of the same type are used to the left and right of the assignment sign. In all other cases, separate fields of records are operated. To refer to an individual record component, you must specify the record name and, through a dot, specify the name of the desired field. Such a name is called a compound name. A record component can also be a record, in which case the distinguished name will contain not two, but more names.

Referencing record components can be simplified by using the with append operator. It allows you to replace the compound names that characterize each field with just field names, and define the record name in the join statement.

Sometimes the content of an individual record depends on the value of one of its fields. In the Pascal language, a record description is allowed, consisting of a common and variant parts. The variant part is specified using the case P of construct, where P is the name of the field from the common part of the record. The possible values ​​accepted by this field are listed in the same way as in the variant statement. However, instead of specifying the action to perform, as is done in a variant statement, the variant fields are specified in parentheses. The description of the variant part ends with the service word end. The field type P can be specified in the heading of the variant part. Records are initialized using typed constants.

4. Sets

The concept of a set in the Pascal language is based on the mathematical concept of sets: it is a limited collection of different elements. An enumerated or interval data type is used to construct a concrete set type. The type of elements that make up a set is called the base type.

A multiple type is described using the Set of function words, for example:

type M = Set of B;

Here M is the plural type, B is the base type.

The belonging of variables to a plural type can be determined directly in the variable declaration section.

Set type constants are written as a bracketed sequence of base type elements or intervals, separated by commas. A constant of the form [] means an empty subset.

A set includes a set of elements of the base type, all subsets of the given set, and the empty subset. If the base type on which the set is built has K elements, then the number of subsets included in this set is equal to 2 to the power of K. The order of listing the elements of the base type in constants is indifferent. The value of a variable of a multiple type can be given by a construction of the form [T], where T is a variable of the base type.

Assignment (:=), union (+), intersection (*), and subtraction (-) operations are applicable to variables and constants of a set type. The result of these operations is a value of the plural type:

1) ['A','B'] + ['A','D'] will give ['A','B','D'];

2) ['A'] * ['A','B','C'] will give ['A'];

3) ['A','B','C'] - ['A','B'] will give ['C'].

The following operations are applicable to multiple values: identity (=), non-identity (<>), contained in (<=), contains (>=). The result of these operations has a boolean type:

1) ['A','B'] = ['A','C'] will give FALSE ;

2) ['A','B'] <> ['A','C'] will give TRUE;

3) ['B'] <= ['B','C'] will give TRUE;

4) ['C','D'] >= ['A'] will give FALSE.

In addition to these operations, to work with values ​​of a set type, the in operation is used, which checks whether the element of the base type to the left of the operation sign belongs to the set to the right of the operation sign. The result of this operation is a boolean. The operation of checking whether an element belongs to a set is often used instead of relational operations.

When multiple data types are used in programs, operations are performed on bit strings of data. Each value of the multiple type in the computer memory corresponds to one binary digit.

Values ​​of a multiple type cannot be elements of an I/O list. In each concrete implementation of the compiler from the Pascal language, the number of elements of the base type on which the set is built is limited.

The initialization of multiple type values ​​is done using typed constants.

Here are some procedures for working with sets.

1. Procedure Exclude(var S: Set of T; I:T);

Removes element I from set S. S is a variable of type "set" and I is an expression of a type compatible with the original type of S. Exclude(S, I) is the same as S : = S - [I], but generates more efficient code.

2. Procedure Include(var S: Set of T; I:T);

Adds an element I to the set S. S is a variable of type "set" and I is an expression of a type compatible with the type S. The Include(S, I) construct is the same as S : = S + [I], but generates more efficient code.

Author: Tsvetkova A.V.

<< Back: Subroutines (Routine parameters. Subroutine parameter types. String type in Pascal. Procedures and functions for string type variables. Records. Sets)

>> Forward: Dynamic memory (Reference data type. Dynamic memory. Dynamic variables. Working with dynamic memory. Untyped pointers)

We recommend interesting articles Section Lecture notes, cheat sheets:

Competition. Crib

Organization theory. Lecture notes

Philosophy. Lecture notes

See other articles Section Lecture notes, cheat sheets.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

The existence of an entropy rule for quantum entanglement has been proven 09.05.2024

Quantum mechanics continues to amaze us with its mysterious phenomena and unexpected discoveries. Recently, Bartosz Regula from the RIKEN Center for Quantum Computing and Ludovico Lamy from the University of Amsterdam presented a new discovery that concerns quantum entanglement and its relation to entropy. Quantum entanglement plays an important role in modern quantum information science and technology. However, the complexity of its structure makes understanding and managing it challenging. Regulus and Lamy's discovery shows that quantum entanglement follows an entropy rule similar to that for classical systems. This discovery opens new perspectives in the field of quantum information science and technology, deepening our understanding of quantum entanglement and its connection to thermodynamics. The results of the study indicate the possibility of reversibility of entanglement transformations, which could greatly simplify their use in various quantum technologies. Opening a new rule ... >>

Mini air conditioner Sony Reon Pocket 5 09.05.2024

Summer is a time for relaxation and travel, but often the heat can turn this time into an unbearable torment. Meet a new product from Sony - the Reon Pocket 5 mini-air conditioner, which promises to make summer more comfortable for its users. Sony has introduced a unique device - the Reon Pocket 5 mini-conditioner, which provides body cooling on hot days. With it, users can enjoy coolness anytime, anywhere by simply wearing it around their neck. This mini air conditioner is equipped with automatic adjustment of operating modes, as well as temperature and humidity sensors. Thanks to innovative technologies, Reon Pocket 5 adjusts its operation depending on the user's activity and environmental conditions. Users can easily adjust the temperature using a dedicated mobile app connected via Bluetooth. Additionally, specially designed T-shirts and shorts are available for convenience, to which a mini air conditioner can be attached. The device can oh ... >>

Energy from space for Starship 08.05.2024

Producing solar energy in space is becoming more feasible with the advent of new technologies and the development of space programs. The head of the startup Virtus Solis shared his vision of using SpaceX's Starship to create orbital power plants capable of powering the Earth. Startup Virtus Solis has unveiled an ambitious project to create orbital power plants using SpaceX's Starship. This idea could significantly change the field of solar energy production, making it more accessible and cheaper. The core of the startup's plan is to reduce the cost of launching satellites into space using Starship. This technological breakthrough is expected to make solar energy production in space more competitive with traditional energy sources. Virtual Solis plans to build large photovoltaic panels in orbit, using Starship to deliver the necessary equipment. However, one of the key challenges ... >>

Random news from the Archive

Tohiba Z4 MiniLED 870K Gaming TVs 07.04.2023

Toshiba has announced the launch of the Z4 MiniLED series of 870K gaming TVs, which boast screens with a 144Hz refresh rate optimal for gaming and representative Game Mode Pro/ALLM/AMD FreeSync/VRR tools, etc.

The LED type mini screen has a number of undoubted advantages, ranging from brighter colors and improved local dimming to better backlighting. The REGZA processor, in turn, provides the highest quality mode of operation with optimization of colors and contrast.

The expected release date for the Z870 MiniLED range is July this year. The sales geography will not be limited to Japan alone, the developer's representatives say on condition of anonymity, without specifying key details such as price, dimensions, exact presentation date, etc.

The brand already has a 100-inch Z870 model introduced in China at the end of 2022. This unit boasts 256 local dimming zones, up to 1 nits of brightness, 400K resolution, 4 percent DCI-P97 coverage, a REGZA engine, and Dolby Vision/Dolby Atmos support. The TV also has a built-in 3 channel sound system. There is an option to connect external speakers via audio outputs and SPDIF ports. Other connectors and interfaces - HDMI 2.1/HDMI 2.1/USB 2.0.

The 100-inch version of the Z870 sold in China is priced at just under $5100.

Other interesting news:

▪ Medical DC/DC Converters Mean Well MDS15/20

▪ Launch of the first public 5G network in the US

▪ comet trail

▪ soft exoskeleton

▪ Vulnerability of Empires

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site RF power amplifiers. Article selection

▪ article How little has been lived, how much has been experienced! Popular expression

▪ article How long will the most dangerous precipitation of the Chernobyl zone decay by half? Detailed answer

▪ article Meadowsweet meadowsweet. Legends, cultivation, methods of application

▪ article Fitter's Probe. Encyclopedia of radio electronics and electrical engineering

▪ article Stable current generator for charging batteries and its application in the repair and design of electronic equipment. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024