Documentation/Calc Functions/RIGHTB

    From The Document Foundation Wiki
    Other languages:


    Function name:

    RIGHTB

    Category:

    Text

    Summary:

    Extracts a sub-string from the right of the supplied text string, with the length of the sub-string specified in bytes.

    Syntax:

    RIGHTB(Text[; Number of Bytes])

    Returns:

    Returns a text string comprising the specified number of bytes from the right side of the supplied text string.

    Arguments:

    Text is a text string (in quotation marks), a number, or a reference to a cell containing one of those types, that is the string from which characters are to be extracted.

    Number of Bytes is a non-negative integer, or a reference to a cell containing a non-negative integer, that is the number of bytes to be extracted. If Number of Bytes is omitted, RIGHTB uses the value 1.

    • If Number of Bytes is non-numeric, then RIGHTB reports a #VALUE! error.
    • If Number of Bytes is a non-integer value, RIGHTB truncates it to an integer value.
    • If Number of Bytes is less than 0, then RIGHTB reports an invalid argument error (Err:502).
    • If Text comprises fewer bytes than the value of Number of Bytes, RIGHTB returns a copy of Text.

    Additional details:

    Details specific to RIGHTB function

    If the specified number of bytes would otherwise lead to extracting only one byte of a two-byte character, RIGHTB instead inserts a space character (Unicode U+0020) at the beginning of the returned string.


    General information about byte-position functions

    Note pin.svg

    Note:
    For convenience, the information in this subsection is repeated on all pages describing Calc’s byte-position functions.

    Calc provides several byte-position text functions, which are intended to be used with double-byte character set (DBCS) languages. These functions are FINDB, LEFTB, LENB,MIDB, REPLACEB, RIGHTB, and SEARCHB. Each has an equivalent "ordinary" text function with a similar name but without the final letter "B".

    Calc considers double-byte characters to be those characters lying within the following Unicode code blocks:

    • Bopomofo Extended (U+31A0 ... U+31BF)
    • Bopomofo (U+3100 ... U+312F)
    • CJK Compatibility Forms (U+FE30 ... U+FE4F)
    • CJK Compatibility Ideographs Supplement (U+2F800 ... U+2FA1F)
    • CJK Compatibility Ideographs (U+F900 ... U+FAFF)
    • CJK Compatibility (U+3300 ... U+33FF)
    • CJK Radicals Supplement (U+2E80 ... U+2EFF)
    • CJK Strokes (U+31C0 ... U+31EF)
    • CJK Symbols and Punctuation (U+3000 ... U+303F)
    • CJK Unified Ideographs Extension A (U+3400 ... U+4DBF)
    • CJK Unified Ideographs Extension B (U+20000 ... U+2A6DF)
    • CJK Unified Ideographs (U+4E00 ... U+9FFF)
    • Enclosed CJK Letters and Months (U+3200 ... U+32FF)
    • Halfwidth and Fullwidth Forms (U+FF00 ... U+FFEF)
    • Hangul Compatibility Jamo (U+3130 ... U+318F)
    • Hangul Jamo (U+1100 ... U+11FF)
    • Hangul Syllables (U+AC00 ... U+D7AF)
    • High Private Use Surrogates (U+DB80 ... U+DBFF)
    • High Surrogates (U+D800 ... U+DB7F)
    • Hiragana (U+3040 ... U+309F)
    • Ideographic Description Characters (U+2FF0 ... U+2FFF)
    • Kanbun (U+3190 ... U+319F)
    • Kangxi Radicals (U+2F00 ... U+2FDF)
    • Katakana (U+30A0 ... U+30FF)
    • Low Surrogates (U+DC00 ... U+DFFF)
    • Private Use Area (U+E000 ... U+F8FF)
    • Yi Radicals (U+A490 ... U+A4CF)
    • Yi Syllables (U+A000 ... U+A48F)

    See Wikipedia's Unicode block page for more information about these blocks.

    In addition, code points U+005C and U+20AC are taken to be double-byte characters if the system language is set to Japanese.

    As noted in ODF 1.2, byte positions are implementation-dependent and so reliance upon them reduces interoperability.

    Examples:

    The following examples are similar to those used for the RIGHT function and demonstrate the consistent behavior of the two functions for single-byte character strings.

    Formula Description Returns
    =RIGHTB("Input string"; 2) Here the function returns the last two bytes of the supplied string. ng
    =RIGHTB(12,345.6789; 5) Here the function returns the last five digits of the supplied number, formatted as a text string. .6789
    =RIGHTB(D1; D2) where cell D1 contains the string "Input string" and cell D2 contains the number 3. Here the function returns the last three bytes of the supplied string. ing
    =RIGHTB("Input string") Here the function returns the last byte of the supplied string. The default value of 1 is applied when the Number argument is omitted. g
    =RIGHTB("Input string"; 0) Here the function returns the empty string.

    The remaining examples demonstrate the behavior of RIGHTB for strings that include double-byte characters. These examples utilize the double-byte characters "中" (Unicode CJK Unified Ideograph-4E2D) and "国" (CJK Unified Ideograph-56FD).

    Formula Description Returns
    =RIGHTB("中国"; 1) Here one byte is only half of a double-byte character and so a space character is returned instead. " "
    =RIGHTB("中国"; 2) Here the function returns the last character of the string, since one double-byte character occupies two bytes. "国"
    =RIGHTB("中国"; 3) Here three bytes constitute one double-byte character and a further byte. The function returns the last character of the string preceded by a space character. " 国"
    =RIGHTB("中国"; 4) Here the function returns both characters of the string, since two double-byte characters occupy four bytes. "中国"

    Related LibreOffice functions:

    FINDB

    LEFTB

    LENB

    MIDB

    REPLACEB

    RIGHT

    SEARCHB

    ODF standard:

    Section 6.7.7, part 2

    Related (or similar) Excel functions:

    RIGHTB