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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Code Pages: del space)
m
 
(4 intermediate revisions by 3 users not shown)
Line 8: Line 8:
 
}}
 
}}
 
__NOTOC__  
 
__NOTOC__  
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 {{AOo}} 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==
Line 30: Line 30:
 
===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 {{AOo}} and {{AOo}} 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.
+
{{AOo}} Basic saves strings as string variables in Unicode. A string variable can store up to 65535 characters. Internally, {{AOo}} 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:
 
Example declaration of a string variable:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
Dim Variable As String
 
Dim Variable As String
</source>
+
</syntaxhighlight>
  
 
You can also write this declaration as:
 
You can also write this declaration as:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
Dim Variable$
 
Dim Variable$
</source>
+
</syntaxhighlight>
  
{{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 {{AOo}} Basic is observed (65535 characters).}}
  
 
==Specification of Explicit Strings==
 
==Specification of Explicit Strings==
Line 54: Line 54:
 
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 (").
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
Dim MyString As String
 
Dim MyString As String
 
MyString = " This is a test"
 
MyString = " This is a test"
</source>
+
</syntaxhighlight>
  
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:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
Dim MyString As String
 
Dim MyString As String
MyString =  "This string is so long that it " + _
+
MyString =  "This string is so long that it " & _
 
             "has been split over two lines."
 
             "has been split over two lines."
</source>
+
</syntaxhighlight>
  
 
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:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
Dim MyString As String
 
Dim MyString As String
 
MyString = "a ""-quotation mark."    ' produces a "-quotation mark
 
MyString = "a ""-quotation mark."    ' produces a "-quotation mark
</source>
+
</syntaxhighlight>
  
 
   
 
   
 
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Strings}}
 
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Strings}}
 
{{PDL1}}
 
{{PDL1}}

Latest revision as of 10:57, 30 January 2021


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