Difference between revisions of "Documentation/BASIC Guide/Strings"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m (String Variables)
(16 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 +
{{DISPLAYTITLE:String Variables}}
 
{{Documentation/BASICGuideTOC/v2
 
{{Documentation/BASICGuideTOC/v2
 
|ShowPrevNext=block
 
|ShowPrevNext=block
Line 5: Line 6:
 
|NextPage=Documentation/BASIC Guide/Numbers
 
|NextPage=Documentation/BASIC Guide/Numbers
 
|lang=block
 
|lang=block
}}<!-- {{DISPLAYTITLE:Strings -->
+
}}
 
+
__NOTOC__
==Strings ==
+
 
+
 
Strings, together with numbers, form the most important basic types of {{OOo}} 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.
 
Strings, together with numbers, form the most important basic types of {{OOo}} 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 ===
+
==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.
 
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===
  
 
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.  
 
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.  
Line 21: Line 20:
 
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.
 
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 ====
+
===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.
 
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 ====
+
===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.
+
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===
  
 
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 {{OOo}} and {{OOo}} Basic.
 
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 {{OOo}} and {{OOo}} Basic.
  
===String Variables ===
+
==String Variables==
  
 
{{OOo}} Basic saves strings as string variables in Unicode. A string variable can store up to 65535 characters. Internally, {{OOo}} Basic saves the associated Unicode value for every character. The working memory needed for a string variable depends on the length of the string.
 
{{OOo}} Basic saves strings as string variables in Unicode. A string variable can store up to 65535 characters. Internally, {{OOo}} Basic saves the associated Unicode value for every character. The working memory needed for a string variable depends on the length of the string.
Line 39: Line 38:
 
Example declaration of a string variable:
 
Example declaration of a string variable:
  
Dim Variable As String
+
<source lang="oobas">
 +
Dim Variable As String
 +
</source>
  
 
You can also write this declaration as:
 
You can also write this declaration as:
  
Dim Variable$
+
<source lang="oobas">
 +
Dim Variable$
 +
</source>
  
{{Documentation/Note|When porting VBA applications, ensure that the maximum allowed string length in {{OOo}} Basic is observed (65535 characters).}}
+
{{Documentation/VBAnote|When porting VBA applications, ensure that the maximum allowed string length in {{OOo}} Basic is observed (65535 characters).}}
  
===Specification of Explicit Strings ===
+
==Specification of Explicit Strings==
  
 
To assign an explicit string to a string variable, enclose the string in quotation marks (").
 
To assign an explicit string to a string variable, enclose the string in quotation marks (").
  
Dim MyString As String
+
<source lang="oobas">
MyString = " This is a test"
+
Dim MyString As String
 +
MyString = " This is a test"
 +
</source>
  
To split a string across two lines, add a plus sign at the end of the first line:
+
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
+
<source lang="oobas">
MyString =  "This string is so long that it" + _
+
Dim MyString As String
              "has been split over two lines."
+
MyString =  "This string is so long that it " & _
 +
            "has been split over two lines."
 +
</source>
  
 
To include a quotation mark (") in a string, enter it twice at the relevant point:
 
To include a quotation mark (") in a string, enter it twice at the relevant point:
  
Dim MyString As String
+
<source lang="oobas">
MyString = "a ""-quotation mark."    ' produces a "-quotation mark
+
Dim MyString As String
 +
MyString = "a ""-quotation mark."    ' produces a "-quotation mark
 +
</source>
 +
 
 +
 +
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Strings}}
 +
{{PDL1}}

Revision as of 08:21, 22 October 2009


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$
Documentation note.png VBA : 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).
Personal tools