About strings and the String class

In programming, a string is an ordered series of characters. You use strings often in your Flash documents and class files to display text in applications, such as within text fields. Also, you can store values as strings that you can use in an application for a variety of purposes. You can put strings directly in your ActionScript code by placing quotation marks around the characters of data. For more information on creating strings, see Creating strings. For information on using text fields, see Using the TextField class.

You can associate each character with a specified character code, which you can also optionally use to display text. For example, the character "A" is represented by the Unicode character code 0041, or 65 in ASCII (American Standard Code for Information Interchange). For more information on character codes and code charts, see www.unicode.org/charts. As you can see, the way you represent strings in a Flash document depends a lot on the character set you choose, and the way you encode characters.

Character encoding refers to the code, or method, for representing a set of characters in a language to representative codes, such as numeric values. The character code (as mentioned in the previous paragraph) is the table of mapped values (such as the ASCII table, where A equals 65). The encoding method deciphers it in a computer program.

For example, each letter in the English language would have a representative numerical code in a character encoding. ASCII encodes each letter, number, and some symbols to 7-bit binary versions of each integer. ASCII is a character set consisting of 95 printable characters and numerous control characters; ASCII is used by computers to represent text.

Like ASCII, Unicode is another way to associate a code with each letter of the alphabet. Because ASCII cannot support large character sets, such as Chinese, the Unicode Standard is a valuable standard to encode languages. Unicode is the standard for character sets that can represent any language set. It is a standard that exists to help development in multiple languages. The character code designates what character it represents, and the standard attempts to provide a universal way to encode characters that are part of any language. Strings could be displayed on any computer system, or platform, or software used. Then, it is up to the program involved (such as Flash or a web browser) to display the character glyph (its visual appearance).

Over the years, the number of characters that Unicode supports has expanded to add support for more (and larger) languages. The character encodings are called Unicode Transformation Format (UTF) and Universal Character Set (UCS), which include UTF-8, UTF-16, and UTF-32. The numbers in UTF encoding represent the number of bits in a unit, and the numbers in a UCS encoding represent bytes.

Strings can be of various lengths in your applications. You can determine the length of your string, although this might vary, depending on what language you're using. Also, you might encounter a terminating character at the end of a string, and this null character doesn't have a value. This terminating character is not an actual character, but you can use it to determine when a string ends. For example, if you're working with socket connections, you might watch for the terminating character to know the end of a string (such as in a chat program).

You can find a sample source file, strings.fla, in the Samples folder on your hard disk. This file shows you how to build a simple word processor that compares and retrieves string and substring selections.

For more information on Strings and the String Class, see the following topics:


Version 8

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001479.html