字符串变量
Strings, together with numbers, form the most important basic types of Apache OpenOffice Basic. A string consists of a sequence of consecutive individual characters. The computer saves the strings internally as a sequence of numbers where each number represents one specific character.
From a Set of ASCII Characters to Unicode
Character sets match characters in a string with a corresponding code (numbers and characters) in a table that describes how the computer is to display the string.
The ASCII Character Set
The ASCII character set is a set of codes that represent numbers, characters, and special symbols by one byte. The 0 to 127 ASCII codes correspond to the alphabet and to common symbols (such as periods, parentheses, and commas), as well as some special screen and printer control codes. The ASCII character set is commonly used as a standard format for transferring text data between computers.
However, this character set does not include a range of special characters used in Europe, such as â, ä, and î, as well as other character formats, such as the Cyrillic alphabet.
The ANSI Character Set
Microsoft based its Windows product on the American National Standards Institute (ANSI) character set, which was gradually extended to include characters that are missing from the ASCII character set.
Code Pages
The ISO 8859 character sets provide an international standard. The first 128 characters of the ISO character set correspond to the ASCII character set. The ISO standard introduces new character sets (code pages) so that more languages can be correctly displayed. However, as a result, the same character value can represent different characters in different languages.
Unicode
Unicode increases the length of a character to four bytes and combines different character sets to create a standard to depict as many of the world's languages as possible. Version 2.0 of Unicode is now supported by many programs — including Apache OpenOffice and Apache OpenOffice Basic.
String Variables
Apache OpenOffice Basic saves strings as string variables in Unicode. A string variable can store up to 65535 characters. Internally, Apache OpenOffice Basic saves the associated Unicode value for every character. The working memory needed for a string variable depends on the length of the string.
Example declaration of a string variable:
Dim Variable As String
You can also write this declaration as:
Dim Variable$
When porting VBA applications, ensure that the maximum allowed string length in Apache OpenOffice Basic is observed (65535 characters). |
Specification of Explicit Strings
To assign an explicit string to a string variable, enclose the string in quotation marks (").
Dim MyString As String MyString = " This is a test"
To split a string across two lines of code, add an ampersand sign (the concatenation operator) and the underscore continuation character at the end of the first line:
Dim MyString As String MyString = "This string is so long that it " & _ "has been split over two lines."
To include a quotation mark (") in a string, enter it twice at the relevant point:
Dim MyString As String MyString = "a ""-quotation mark." ' produces a "-quotation mark
Content on this page is licensed under the Public Documentation License (PDL). |