CHR, ChrW functions

Source: Internet
Author: User
Tags chr error handling exception handling
Chr, ChrW functions

The Visual Basic language character function that returns the character associated with the specified character code.   The CHR, ChrW function returns the character associated with the specified character code. Public Function Chr (ByVal charcode As Integer) as char public Function ChrW (ByVal charcode As Integer) as CharParametersCharCode must be selected. An Integer expression that represents a "code bit" or character code for a character. If the charcode is not within the valid range, a ArgumentException error occurs. The effective range of CHR is 0 to 255, and the effective range of ChrW is 32768 to 65535.ExceptionException type error number condition ArgumentException 5 CharCode <-32768 or > 65535 (for ChrW).   ArgumentException 5 CharCode < 0 or > 255 (for CHR). If you are upgrading a Visual Basic 6.0 application that uses unstructured error handling, see the "Error Number" column. (You can compare error numbers based on the Number property (the Err object). However, if possible, you should consider replacing this error control with a structured exception handling overview of Visual Basic.edit this paragraph note Data TypeThe asymmetric range accepted by charcode compensates for storage differences between the short data type (Visual Basic) and the Integer data type (Visual Basic). For example,-29183 is short, but +36353 is Integer.   This also helps with Visual Basic 6.0 compatibility. CHR uses the Encoding class in the System.Text namespace to determine whether the current thread is using a single-byte character set (SBCS) or a double-byte character set (DBCS). The charcode is then used as a code bit in the corresponding character set. For SBCS characters, the range is 0 to 255, and for DBCS characters, the range is 32768 to 65535.   For a chart of single-byte ASCII characters, see ASCII character code. The return value depends on the current thread's code page, which is contained in the ANSICodePage property of the TextInfo class in the System.Globalization namespace.   ANSICodePage can be obtained by specifying System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage. ChrW to CharCode as a Unicode code bit. The scope is independent of the Culture and code page settings of the current thread.   The values in the range 32768 through 1 are treated in the same way as the values in the range +32768 through +65535. The numbers from 0 to 31 are the same as the standard nonprinting ASCII code.   For example, CHR (10) returns the line feed character. Note the ChrB function in the earlier version of Visual Basic returns a single byte. It is primarily used to convert strings in Double-byte character set (DBCS) applications. All strings in Visual Basic and the. NET Framework are in Unicode form and no longer support ChrB. SampleThe following example uses the CHR function to return the character associated with the specified character code.   Visual Basic copies code Dim Associatedchar as Char ' Returns ' A '.   Associatedchar = Chr ' Returns ' a '.   Associatedchar = Chr () ' Returns ' > '.   Associatedchar = Chr ' Returns '% '. Associatedchar = CHR (37) requires namespaces: Microsoft.VisualBasic modules: Strings assemblies: Visual Basic Runtime Library (at Microsoft. VisualBasic.dll) The CHR function returns the character corresponding to the specified ANSI character code.Chr (CharCode)    CharCodeA parameter is a number that can identify a character. Indicates that a number from 0 to 31 represents a standard, non-printing ASCII code. For exampleChr (10)Returns the line feed character. The following example usesChrfunction returns the character corresponding to the specified character code: Dim Mycharmychar =Chr (65)' Return A. MyChar =Chr (97)' Return a. MyChar =Chr (62)' Back to >. MyChar =Chr (37)' Returns%.pay attention to ChrBFunctions are used in conjunction with the byte data contained in a string.ChrBdoes not return one or two bytes of characters, but always returns a single byte character.ChrWis provided for a 32-bit platform that uses Unicode characters. Its argument is a Unicode (wide-character) character code, so you can avoid converting ANSI to Unicode characters. 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.