search
HomeCommon ProblemWhat is the structure of a string?

What is the structure of a string?

Jul 18, 2020 pm 12:08 PM
structure

String is a linear storage structure, because the characters in the string also have a "one-to-one" logical relationship. However, unlike the linear storage structure we learned before, the string structure is only used to store character type data.

What is the structure of a string?

#In the data structure, strings are stored in a separate storage structure, which is called a string storage structure. The string here refers to the string.

Strictly speaking, the string storage structure is also a linear storage structure, because the characters in the string also have a "one-to-one" logical relationship. However, unlike the linear storage structure we learned before, the string structure is only used to store character type data.

No matter which programming language you learn, strings are always the most manipulated. In the data structure, some special strings are named according to the number and characteristics of the characters stored in the string, for example:

  • Empty string: stores a string of 0 characters, such as S = "" (double quotes next to each other);

  • Space string: a string containing only space characters, such as S = " " (double quotes contain 5 spaces);

  • Substring and main string: Suppose there are two strings a and b. If a string consisting of several consecutive characters can be found in a that is exactly the same as b, then a is said to be the main string of b. b is a substring of a. For example, if a = "shujujiegou", b = "shuju", since a also contains "shuju", string a and string b are the relationship between the main string and the substring;

It should be noted that the space string is different from the empty string. The space string contains characters, but they are all spaces. In addition, only if string b appears entirely in string a, can it be said that b is a substring of a. For example, "shujiejugou" and "shuju" are not related to the main string and substring.

In addition, for two strings with a relationship between a main string and a substring, you are usually asked to use an algorithm to find the position of the substring in the main string. The position of the substring in the main string refers to the position of the first character of the substring in the main string.

For example, string a = "shujujiegou", string b = "jiegou", through observation, you can judge that a and b are the relationship between the main string and the substring, and at the same time, the substring b is located at the 6th position in the main string a. position, because in string a, the position of the first character 'j' of string b is 6.

Specific implementation of string storage structure

To store a string, the data structure contains the following three specific storage structures:

  • Fixed-length sequential storage: In fact, it is stored in an ordinary array (also known as a static array). For example, the code for using ordinary data to store strings in C language is char a[20] = "data.biancheng.net";

  • Heap allocated storage: use dynamic arrays to store strings;

  • Block chain storage: use linked list to store strings;

For more related knowledge, please visit:PHP Chinese website !

The above is the detailed content of What is the structure of a string?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools