Generate a character in REALbasic

As of REAL Studio 2010, the best way to programmatically generate a character is by calling the method "Chr" on a TextEncoding. You may get a particular TextEncoding by name through Encodings. You pass the decimal number of the code point of the needed character.

There are various encodings, but the normal one within REALbasic is UTF-8.

Example, to generate the Tab character using code point 9:


To generate a bullet (•):


To generate an ankh (☥):


Beware of the built-in command "Chr" which you call directly in your code without any class prefix. That command is outmoded, and only works with the first 128 characters of ASCII. "Chr" fails with accented characters, bullets, or any of the million other Unicode characters. Make a habit of calling "Encodings.UTF8.Chr" instead.

Tip: For you Mac users, UnicodeChecker is a wonderful tool for looking up any Unicode character. This program is a nice GUI wrapper around a database of the Unicode characters. You can search by name such as "bullet". Free of cost.

No comments:

Post a Comment