Chr

From Xojo Documentation

Revision as of 19:16, 19 November 2009 by WikiSysop (talk) (Examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!


Description

Returns the character whose ASCII value is passed.


Syntax

result=Chr(value)

Part Type Description
result String The character whose ASCII value was passed.
value Integer The numeric value ("code point") of the character you want, in the range 0-127.

If you pass a number that is not an Int32, REALbasic will convert it to an Int32 and display an issue in the Run tab when you select Analyze Project in the IDE.


Notes

The Chr function returns the character whose value is specified. It is valid for the standard ASCII character set only. For this reason, Chr may return unexpected results unless you use it only for ASCII values (0-127).


In general, you should use the Chr method of the TextEncoding class. With it, you specify both the encoding and the character code in that encoding. Please see the example in the TextEncoding class and the last line in this example. In effect, the Chr function supports the special case in which the encoding is ASCII and value is less than 128.

The Chr function will return a single byte string when running on single byte systems and return a double byte string when running on double byte systems. If you need to get a single byte string regardless of whether the system software is single or double byte, use the ChrB function.


Examples

These examples use the Chr function to return the characters whose ASCII values are specified.

Tab=Chr(9) //returns a tab
CR=Chr(13) //returns carriage return
CR=Encodings.ASCII.Chr(13) //also returns carriage return

See Also

Asc, Encoding, InStr, Left, Len, Mid, Right functions; EndOfLine, TextEncoding classes; Encodings module.