Chr function
Returns a String containing the character associated with the specified character code.
Syntax
Chr(charcode)
ChrB(charcode)
ChrW(charcode)
The required charcode argument is a Long that identifies a character.
Remarks
Numbers from 0–31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character. The normal range for charcode is 0–255. However, on DBCS systems, the actual range for charcode is -32768–65535.
Note
The ChrB function is used with byte data contained in a String. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte.
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.
Note
Visual Basic for the Macintosh does not support Unicode strings. 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. Instead, ChrW(n) attempts a "best guess" for Unicode values n greater than 127. Therefore, you should not use ChrW in the Macintosh environment.
The functions Asc(), AscB(), and AscW() are the opposite of Chr(), ChrB(), and ChrW(). The Asc() functions convert a string to an integer.
Example
This example uses the Chr function to return the character associated with the specified character code.
Dim MyChar
MyChar = Chr(65) ' Returns A.
MyChar = Chr(97) ' Returns a.
MyChar = Chr(62) ' Returns >.
MyChar = Chr(37) ' Returns %.
See also
- Character set (0 - 127)
- Character set (128 - 255)
- Functions (Visual Basic for Applications)
- Asc(), AscB(), and AscW() functions
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기