Chr — ���������� ������ �� ��� ����
(PHP 4, PHP 5, PHP 7)
chr � Возвращает символ по его коду
Описание
Возвращает строку из одного символа, код которого задан аргументом ascii .
Эта функция дополняет функцию ord() .
Список параметров
� асширенный ASCII-код.
Значения за пределом диапазона (0..255) должны быть подибово сложены (bitwise AND) с 255, что соответствует такому алгоритму:
Возвращаемые значения
Возвращает символ по его коду.
Примеры
Пример #1 Пример использования chr()
= «Эта строка заканчивается на escape: » ;
$str .= chr ( 27 ); /* добавляет символ escape в конец $str */
/* Но обычно лучше использовать такую конструкцию */
$str = sprintf ( «The string ends in escape: %c» , 27 );
?>
Пример #2 Поведение при переполнении
� езультат выполнения данного примера:
FPublisher
Web-����������: ���� ������
������������ PHP
chr � ���������� ������ �� ��� ����
��������
���������� ������ �� ������ �������, ��� �������� ����� ���������� ascii .
������ #1 ������ ������������� chr()
= «��� ������ ����������� escape: » ;
$str .= chr ( 27 ); /* ��������� escape-������ � ����� $str */
/* �� ����� ����� ������������ ����� ����������� */
$str = sprintf ( «The string ends in escape: %c» , 27 );
?>
������� ASCII-����� �� ������ ����� �����: � http://www.asciitable.com.
��� ������� ��������� ������� ord(). ��. ����� �������� ������� %c ������� sprintf().
3.9.3 ��������� �������
��������� ������� VBA, Asc(), Chr(), InStr(), Len(), LCase(), UCase(), Replace(), Trim()
��� � �������� ����� ������������ �������. ��������� ��� ���������, � ����� �� ���������� ����� ������.
- ASC() � ��� ������� ��������� ������� �������� ��� ��� ����������� �������. ��������, ASC(«D») ������ 68. ��� ������� ������ ������������ ��� ����, ����� ���������� ��������� ��� ���������� �����. ������ ��� ������������ ������ � �������� Chr(), ������� ���������� �������� �������� � ���������� ������ �� ����������� ��� ��������� ����. ��������, ����� ��� � Excel ��������� �������� � ������ � A1 �� A20 ��������������� ����� �������� �������� �� A �� �:
Chr — ���������� ������ �� ��� ����
chr � ���������� ������ �� ��� ����
��������
���������� ������ �� ������ �������, ��� �������� ����� ���������� ascii.
������ #1 ������ ������������� chr()
= «��� ������ ����������� escape: » ;
$str .= chr ( 27 ); /* ��������� escape-������ � ����� $str */
/* �� ����� ����� ������������ ����� ����������� */
$str = sprintf ( «The string ends in escape: %c» , 27 );
?>
������� ASCII-����� �� ������ ����� �����: � http://www.asciitable.com.
��� ������� ��������� ������� ord() . ��. ����� �������� ������� %c ������� sprintf() .
������� Chr
������� Chr � ������� ����������� ���� � ������. ���������:
function Chr(B: Byte) : Char;
������� ���������� ������, ASCII-��� �������� ������ � ��������� �.
���������� ������� �� ���� ������� �������������� ����� � ������� Chr ���� ���������� ��� ����, ����� ��������� ��������� �������� � ASCII-������ ��������. � ��������� �������������� ������� � �������������� ����� ����� ��������� ���������� �� ������������� ������� Chr. ������ ��� �� ��������� ���������� � �� ��� ��� ������ ������������.
��� ���������� ������ �� ����
�������, �� ��� ���������� ))))
�� �� �� �����, ��� ������� ��� ����� � ������� ������� Chr. ��� ����� ���� ����� ASCII-��� �������. � ����� ����� ���������� ������ �� ASCII-���� ��������� �������:
����� �� ������� � ������� Chr ����� 100 — ASCII-��� ������� d. � �� ������ ��������, ��������������, ������. �� ���� ����� ���������� ���� ������� � ���������� Sym ����� ������ d.
��� ������� ��������� ������� ASCII-���� �������� �� ‘0’ �� ‘9’.
Chr — ���������� ������ �� ��� ����
���������� ������, ��������������� ���������� ASCII-����.
ASCIIcode | ASCII-��� ������� � ��������� 0-255. |
�����: | ���������� ������, ���������� ������ ���������� ASCII ����. |
������: | ���������� ������ ������ � ������������� �������� @error ������ 1, ���� ASCII-��� ������ 255. |
Chr(48) == «0»
Chr(57) == «9»
Chr(65) == «A»
Chr(90) == «Z»
Chr(97) == «a»
Chr(122) == «z» � �.�.
�������� ���������� ��� ��������� ������ ������� ASCII ��������.
$sText = «»
For $i = 65 To 90
$sText &= Chr ( $i ) ; ������������ ������ � ����������
Next
; ���������� ������� � �� ������ �� 65 �� 90
MsgBox ( 4096 , «������� �� ��������� ����» , $sText )
����� �������
�� � ���� ��� ����������� ���� ������, ������� ��������� ������� � ������������ ����� ����� (integer) � ������� ����� (real). ������ ���������� ��� ������, ����������� ������� � ������������ ��������� �������. ������� � ��� ��� ����� � ������, ������� �� ����� ������� �� ����������. ��� ���� ����� ������ � ��������� ���������� ���������� ���������� ������� ��� ��� ���������� ��� ������ Char.
������ �4. ���������� ���������� �X� � ��������� ��� ��� ��� ������ Char. Char � ��� ������, ������� ��������� ������� �������. � ������ ������ � ���������� �X� �� ����� ���������� �� �����-�� �����, � �������.
� ������ �7 �� ��������� ���������� �X� �������� ��������� ����� L. ��� ������, ������� ���������� �������� � ����������, ����������� ������� � ���������. �������, ��� ����� �� ����������� ���������� �������� ��������, �� ����� � ��������� �� �������.
� ������ �8 ������� �� ����� ��������, ������� �� ��������� ���������� X, �.�. ���������� �� ����� ��������� ����� L.
������ �9. ������� Ord, ��������������� ����� � �� �������� ���. ���� ���� ���� � �������� ����� ���������� � ������� ������� ASCII, ������� ��������� ����. ASCII (American Standard Code for Information Interchange) — ������������� ��������, �������� ��� ����������� ��������� ����������. �� ���� �������, ����� ������� ����� ���� ���������� �������� ���. � ����� ������� ���������� N ������������� �������� ������� Ord (L) �.�. (���) ����� �L� (�� ������� ASCII ��� ����� �L� — 76).
� ������ �10 ������� �������� ���������� �N� (�.�. �������� ��� ����� �L�) �� �����.
������ �11. ������� Chr �������������� ������� Ord. ��� ������� ����� ��������������� �������� ��� ������� � ��� ������. � ���������� N � ��� ������� ��� ����� �L�. C ������� ������� Chr �� ����������� ���� ��� � ����� � ������� � � ���������� ���������� X. ����� �������, � ������ �12 �� ����� ��������� ����� �L�
���������� � ���������.
� ����������� ���� ������� ������� Ord ���������� � �������� �������� ��� ���������� �X�, ������� ��������� �������� ��������� ����� �L�. ����� ������ ������� Ord ���������� �X� ����� � ������� ������� (������ �9). ������ ������ ���������� ����� �������� �������� ������, ��� �������� ���������� ��������. ���� ������ ���������� ��������� �� ������ � ������� ������, �� � � ���������. ����� ������� ��������� ����� �������� ���:
������� Chr Chr function
���������� �������� ���� String, ������� �������� ������, ��������� � ��������� ����� �������. Returns a String containing the character associated with the specified character code.
��������� Syntax
Chr(charcode) Chr(charcode)
ChrB(charcode) ChrB(charcode)
ChrW(charcode) ChrW(charcode)
��������� �������� charcode ������������ ����� �������� ���� Long, ������� ���������� ������. The required charcode argument is a Long that identifies a character.
���������� Remarks
����� 0�31 ������������� ����������� ���������� ����� ASCII. Numbers from 0�31 are the same as standard, nonprintable ASCII codes. ��������, Chr(10) ���������� ������ �������� ������. For example, Chr(10) returns a linefeed character. ���������� �������� ��� charcode ���������� 0�255. The normal range for charcode is 0�255. �� � �������� ������������ ��������� (DBCS) ����������� �������� ��� charcode ���������� -32 768�65 535. However, on DBCS systems, the actual range for charcode is -32768�65535.
������� ChrB ������������ � ��������� �������, ������������� � �������� String. The ChrB function is used with byte data contained in a String. ������ �����, ������� ����� �������� �� ������ ��� ���� ����, ChrB ������ ���������� ���� ����. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte.
������� ChrW ���������� ���������� String, ������� �������� ���� �������. ���������� ���������� ���������, �� �������������� ������; � ���� ������ ������� �������� ��� ��, ��� ������� Chr. The ChrW function returns a String containing the Unicode character except on platforms where Unicode is not supported, in which case, the behavior is identical to the Chr function.
Visual Basic ��� macOS �� ������������ ������ �������. Visual Basic for the Macintosh does not support Unicode strings. ������� ������� ChrW(n) �� ����� ���������� ��� ������� Unicode ��� �������� n � ��������� 128�65 535, ��� ��� ���������� � ����� Windows. Therefore, ChrW(n) cannot return all Unicode characters for n values in the range of 128�65,535, as it does in the Windows environment. ������ ����� ChrW(n) ���������� «��������� ������» ��� �������� ������� ������ 127. Instead, ChrW(n) attempts a «best guess» for Unicode values n greater than 127. � ����� � ���� �� ������� ������������ ChrW � macOS. Therefore, you should not use ChrW in the Macintosh environment.
������ Example
� ������ ������� ������� Chr ���������� ����, ��������������� ���������� ���� �����. This example uses the Chr function to return the character associated with the specified character code.
��. ����� See also
��������� � �������� ����� Support and feedback
���� ������� ��� ������, ���������� Office VBA ��� ���� ������? Have questions or feedback about Office VBA or this documentation? ����������� �� ������ �������� ��������� ��������� � �������� ������� ��. � ������ ��������� Office VBA � �������� �����. Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Chr — ���������� ������ �� ��� ����
Python 3
���������� ������ (� ���� ������), ��� ������� ���� ��� ������ ����� ���������� ������ *i*. �������� ������ ������������� � �������� �� 0 �� 1,114,111 ( 0x10FFFF ), � ��������� ������ ������������ ���������� ValueError.
Python 2
���������� ������ (� ���� ������), ��� ASCII ��� ����� ���������� ������ *i*. �������� ������ ������������� � �������� �� 0 �� 255 ������������, � ��������� ������ ������������ ���������� ValueError. ��� ��������� ���� unicode ����������� unichr().
�������
������� ����� �������� � ord().
���� � ��� ����, ��� �������, ������ ������������� � ��������� ��������.
FPublisher
Web-����������: ���� ������
������������ PHP
chr � ���������� ������ �� ��� ����
��������
���������� ������ �� ������ �������, ��� �������� ����� ���������� ascii .
������ #1 ������ ������������� chr()
= «��� ������ ����������� escape: » ;
$str .= chr ( 27 ); /* ��������� escape-������ � ����� $str */
/* �� ����� ����� ������������ ����� ����������� */
$str = sprintf ( «The string ends in escape: %c» , 27 );
?>
������� ASCII-����� �� ������ ����� �����: � http://www.asciitable.com.
��� ������� ��������� ������� ord(). ��. ����� �������� ������� %c ������� sprintf().