Text Functions

This section contains descriptions of the Text functions.

若要使用此指令...

[插入] - [函式] - [類別] [文字]


Using double quotation marks in formulas

To include a text string in a formula, place the text string between two double quotation marks (") and Calc takes the characters in the string without attempting to interpret them. For example, the formula ="Hello world!" displays the text string Hello world! in the cell, with no surrounding double quotation marks.

The more complex formula =CONCATENATE("Life is really simple, "; "but we insist on making it complicated "; "(Confucius).") concatenates three individual strings in double quotation marks, outputting Life is really simple, but we insist on making it complicated (Confucius).

To place a literal double quotation mark within a string inside a formula, two methods can be used:

  1. You can "escape" the double quotation mark with an additional double quotation mark, and Calc treats the escaped double quotation mark as a literal value. For example, the formula ="My name is ""John Doe""." outputs the string My name is "John Doe". Another simple example is the formula =UNICODE("""") which returns 34, the decimal value of the Unicode quotation mark character (U+0022) — here the first and fourth double quotation marks indicate the beginning and end of the string, while the second double quotation mark escapes the third.

  2. You can use the CHAR function or the UNICHAR function to insert a double quotation mark. For example, the formula =UNICHAR(34) & "The Catcher in the Rye" & UNICHAR(34) & " is a famous book by J. D. Salinger." displays the string "The Catcher in the Rye" is a famous book by J. D. Salinger.

Be aware that Calc's AutoCorrect function may modify double quotation marks. AutoCorrect should not change the double quotation marks within formula cells but may change those used in non-formula cells containing text. For example, if you copy a string that is surrounded by some other form of typographical double quotation marks, such as the left double quotation mark (U+201C) and the right double quotation mark (U+201D), and then paste into a formula cell, an error may result. Open the Double Quotes area of the Tools - AutoCorrect Options - Localized Options dialog to set the characters used to automatically correct the start and end typographical double quotation marks. Uncheck the Replace toggle button to disable the feature.

Empty string and blank cells

Cells with the empty string ("") are not equivalent to blank cells. When searching or calculating with text, the empty string "" is the text with length zero.

For example, when the formula in A1 returns the empty string "", the following applies:

=ISBLANK(A1) returns FALSE. The cell is not blank.

=ISFORMULA(A1) returns TRUE. The cell is a formula.

=ISLOGICAL(A1) returns FALSE. Not a logical value.

=ISNONTEXT(A1) returns FALSE. The cell has the empty string.

=ISNUMBER(A1) returns FALSE. Not a number.

=ISTEXT(A1) returns TRUE. The cell has the empty string, calculated by a formula.

=LEN(A1) returns 0. The length of the empty string is 0.

ARABIC

Returns the numeric value corresponding to a Roman number expressed as text.

ASC

Converts double-byte (full-width) characters to single-byte (half-width) ASCII and katakana characters.

BAHTTEXT

Converts a number to Thai text, including the Thai currency names.

BASE

Converts a positive integer to a specified base into a text from the numbering system. The digits 0-9 and the letters A-Z are used.

CHAR

Converts a number into a character according to the current code table. The number can be a two-digit or three-digit integer number.

CLEAN

All non-printing characters are removed from the string.

CODE

Returns a numeric code for the first character in a text string.

CONCATENATE

Combines several text strings into one string.

DECIMAL

Converts text that represents a number in a numeral system with the given base radix to a positive integer. The radix must be in the range 2 to 36. Spaces and tabs are ignored. The Text field is not case-sensitive.

DOLLAR

Converts a number to a string representing the amount in the currency format, rounded to a specified decimal places, using the decimal separator that corresponds to the current locale setting. In the Value field enter the number to be converted. Optionally, you may enter the number of decimal places in the Decimals field. If no value is specified, all numbers in currency format will be displayed with two decimal places.

EXACT

Compares two text strings and returns TRUE if they are identical. This function is case-sensitive.

FIND

Returns the position of a string of text within another string.You can also define where to begin the search. The search term can be a number or any string of characters. The search is case-sensitive.

FIXED

Returns a number as text with a specified number of decimal places and optional thousands separators.

JIS

Converts single-byte (half-width) ASCII or katakana characters to double-byte (full-width) characters.

LEFT

Returns the first character or characters of a text.

LEN

Returns the length of a string including spaces.

LOWER

Converts all uppercase letters in a text string to lowercase.

PROPER

Capitalizes the first letter in all words of a text string.

REGEX

Matches and extracts or optionally replaces text using regular expressions.

REPLACE

Replaces part of a text string with a different text string. This function can be used to replace both characters and numbers (which are automatically converted to text). The result of the function is always displayed as text. If you intend to perform further calculations with a number which has been replaced by text, you will need to convert it back to a number using the VALUE function.

REPT

Repeats a character string by the given number of copies.

RIGHT

Returns the last character or characters of a text.

ROMAN

Converts a number into a Roman numeral. The value range must be between 0 and 3999. A simplification mode can be specified in the range from 0 to 4.

SEARCH

Returns the position of a text segment within a character string. You can set the start of the search as an option. The search text can be a number or any sequence of characters. The search is not case-sensitive. If the text is not found, returns error 519 (#VALUE).

SUBSTITUTE

Substitutes new text for old text in a string.

T

This function returns the target text, or a blank text string if the target is not text.

TEXT

Converts a value into text according to a given format.

TRIM

Removes spaces from a string, leaving only a single space character between words.

UNICHAR

Converts a code number into a Unicode character or letter.

UNICODE

Returns the numeric code for the first Unicode character in a text string.

UPPER

Converts the string specified in the text field to uppercase.

VALUE

Converts the string representation of a number to numeric form. If the supplied string is a valid date, time, or date-time, the corresponding date-time serial number is returned.

WEBSERVICE

Get some web content from a URI.

FILTERXML

Apply a XPath expression to a XML document.

ENCODEURL

Returns a URL-encoded string.

LEFTB

傳回雙位元字元集文字的第一個字元。

tip

This function is available since LibreOfficeDev 4.2.


Syntax

LEFTB("Text" [; Number_bytes])

Text 是要傳回初始部份字串的文字。

Number (選擇性) 指定要 LEFTB 擷取的字元數,以位元為單位。若未定義此參數,則傳回一個字元。

Example

=LEFTB("中国";1) returns " " (1 byte is only half a DBCS character and a space character is returned instead).

=LEFTB("中国";2) returns "中" (2 bytes constitute one complete DBCS character).

=LEFTB("中国";3) returns "中 " (3 bytes constitute one DBCS character and a half; the last character returned is therefore a space character).

=LEFTB("中国";4) returns "中国" (4 bytes constitute two complete DBCS characters).

=LEFTB("office";3) returns "off" (3 non-DBCS characters each consisting of 1 byte).

LENB

在雙位元字元集的語言,傳回用來表達文字字串內的字元的位元數。

tip

This function is available since LibreOfficeDev 4.2.


Syntax

LEN("Text")

Text 是要測定長度的文字。

Example

LENB("中") 傳回 2 (一個雙位元字元集字元由兩位元構成)。

LENB("台灣") 傳回 4 (兩個雙位元字元集字元,各由兩位元構成)。

LENB("office") 傳回 6 (六個非雙位元字元集字元,每個一位元)。

=LENB("Good Afternoon") 傳回 14。

=LENB(12345.67) 傳回 8。

MID

傳回文字內的文字字串。參數可指定字元的起始位置和數量。

Syntax

MID("Text"; Start; Number)

Text 是含有要擷取字元的文字。

Start 是要擷取的第一個字元在 Text 中的位置。

Number 指定擷取文字的字元數。

Example

=MID("office";2;2) 傳回 ff。

MIDB

傳回雙位元組字元集文字內的文字字串。參數指定字元的起始位置和數量。

tip

This function is available since LibreOfficeDev 4.2.


Syntax

MIDB("Text"; Start; Number_bytes)

Text 是含有要擷取字元的文字。

Start 是要擷取的第一個字元在 Text 中的位置。

Number_bytes 指定 MIDB 從 Text 傳回的文字字元數量 (以位元為單位)。

Example

=MIDB("中国";1;0) returns "" (0 bytes is always an empty string).

=MIDB("中国";1;1) returns " " (1 byte is only half a DBCS character and therefore the result is a space character).

=MIDB("中国";1;2) returns "中" (2 bytes constitute one complete DBCS character).

=MIDB("中国";1;3) returns "中 " (3 bytes constitute one and a half DBCS character; the last byte results in a space character).

=MIDB("中国";1;4) returns "中国" (4 bytes constitute two complete DBCS characters).

=MIDB("中国";2;1) returns " " (byte position 2 is not at the beginning of a character in a DBCS string; 1 space character is returned).

=MIDB("中国";2;2) returns " " (byte position 2 points to the last half of the first character in the DBCS string; the 2 bytes asked for therefore constitutes the last half of the first character and the first half of the second character in the string; 2 space characters are therefore returned).

=MIDB("中国";2;3) returns " 国" (byte position 2 is not at the beginning of a character in a DBCS string; a space character is returned for byte position 2).

=MIDB("中国";3;1) returns " " (byte position 3 is at the beginning of a character in a DBCS string, but 1 byte is only half a DBCS character and a space character is therefore returned instead).

=MIDB("中国";3;2) returns "国" (byte position 3 is at the beginning of a character in a DBCS string, and 2 bytes constitute one DBCS character).

=MIDB("office";2;3) returns "ffi" (byte position 2 is at the beginning of a character in a non-DBCS string, and 3 bytes of a non-DBCS string constitute 3 characters).

RIGHTB

傳回雙位元字元集 (DBCS) 文字的最後幾個字元。

tip

This function is available since LibreOfficeDev 4.2.


Syntax

RIGHTB("Text" [; Number_bytes])

Text 是指要傳回右側部分字串的文字。

Number_bytes (optional) specifies the number of characters you want RIGHTB to extract, based on bytes. If this parameter is not defined, one byte is returned.

Example

RIGHTB("台灣";1) returns " " (一位元只是一個雙位元字元集字元的一半,因此只傳回一個空白字元)。

RIGHTB("台灣";2) returns "灣" (兩位元構成一個完整的雙位元組字元集的字元)。

RIGHTB("台灣";3) returns " 灣" (三位元構成半個加一個雙位元組字元集的字元;因此針對那半個傳回空白字元)。

RIGHTB("台灣";4) 傳回 "台灣" (四位元構成兩個完整的雙位元組字元集的字元)。

RIGHTB("office";3) 傳回 "ice" (三個非雙位元字元集字元,每個一位元)。