Openoffice basic string functions

Written by violet mabe
  • Share
  • Tweet
  • Share
  • Email

OpenOffice Basic is a programming language for automating OpenOffice that has many similarities to Microsoft's Visual Basic for Applications, which is used to automate Microsoft Office. When programming in OpenOffice Basic, some common functions you will use are the string functions, which allow you to manipulate strings of text in various ways.

Other People Are Reading

Functions for Analyzing Strings

When you want to get information about a string, one common function you will frequently use is Len(string), which returns a number representing the length of the string.

Functions for Getting and Using ASCII Codes

There are two functions for retrieving and using ASCII Codes, which represent characters as numbers. Asc(string) returns the ASCII code for the first character of the specified string. Chr(number) takes a number representing a specific ASCII character and returns the character it represents as a string.

Functions for Finding Text in Strings

Another method of analysing strings is to search a string for a particular character or set of characters. To find a character or set of characters within a string, use the "InStr" function, which takes two forms: InStr(string, searchstring) and InStr(startposition, string, searchstring). The first form starts at the first character and searches for searchstring, and the second form starts at the character specified in startposition (a number), and searches for searchstring. For example, InStr(8, MyString, ":") searches MyString for a colon (":") starting from the eighth character in the string, whereas InStr(MyString, ":") searches for a colon starting from the first character.

Functions for Accessing String Parts

When you want to access just one part of a string, there are three functions you can use. Left(string, length) returns the number of characters specified in length from the specified string, starting from the left, or first character. Right(string, length) returns the number of characters specified in length from the specified string, starting from the right, or last character, and counting backwards. Mid(string, start, length) returns the number of characters specified in length from the specified string, starting from the position specified in start. Therefore Left("Something", 4) returns "Some", Right("Something", 4) returns "hing", and Mid("Something", 3, 3) returns "eth".

Functions for Formatting Strings

When you have a string that contains a specific type of information, such as a date or a currency amount, you may wish to make sure that the string is formatted a specific way. The Format(string, format) function does this, using a string for the format that uses some special characters to tell the program exactly how to format the string. Some of the most common format characters are "0", which specifies a number in that position and a "0" if no number exists; "#", which specifies a number in that position only if a number is present; a period, which represents a decimal place; a comma, which represents a thousands separator (as in 1,000.00); and "$", which represents the currently configured currency symbol based on the user's location settings. You can also format dates using strings like "dd-mm-yyyy".

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.