search
HomeCommon ProblemHow do strings compare in size?

How do strings compare in size?

Mar 05, 2019 pm 03:50 PM
string

How do strings compare in size?

Character comparison refers to the operation of comparing the size of a single character or string in dictionary order. Generally, the size of the ASCII code value is used as the standard for character comparison.

When comparing strings, the size of the strings is compared starting from the first character on the left. The larger one is larger and the smaller one is smaller. If they are equal, continue to compare the following characters;

For example, if ABC and ACDE are compared, if the first character is the same, continue to compare the second character. Since the second character is larger than the next string, the comparison will not continue. The result is that the latter string is larger. Another example is the comparison between ABC and ABC123. After comparing three characters, the first string ends, so the next string is larger.

So, the length cannot directly determine the size. The size of the string is determined by the frontmost character from the left.

When comparing two strings, pay attention to the following points:

1. When comparing two strings of different lengths, the longer string is not necessarily "big". For example, A$ is "ABCE" and B$ is "ABCDEF". When comparing A$ with B$, the 4th character of A$ is "E", the 4th character of B$ is "D", and "D"A $. Even though B$ is longer than A$.

2. When the string contains spaces, spaces are also included in the comparison. For example, A$-"t-ABOOK"u (indicates a space), B$-"A-BOOK", displays A$>B$.

3. There is a difference between the ASCII code values ​​of uppercase letters and lowercase letters, so "yes" > "YEs".

4. When a string is composed entirely of uppercase (or lowercase) English letters, the order of the strings is the same as their order in the dictionary.

5. Strings composed of Chinese characters can be compared. Such as "Li Hong"

The above is the detailed content of How do strings compare in size?. 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)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!