RIGHTB
Returns the rightmost characters of a text string based on a number of bytes. Each double-byte character (DBCS) counts as 2 bytes; single-byte characters count as 1.
RIGHTB(text, [num_bytes])Arguments
textThe text from which to extract the rightmost characters.num_bytesThe number of bytes to extract (default 1). Must be ≥ 0.(optional)
=RIGHTB("Excel",3)Returns the last 3 bytes
=RIGHTB("日本語",2)1 double-byte character = 2 bytes
=RIGHTB("AB日本",4)2 double-byte characters = 4 bytes
- •On systems without DBCS support, RIGHTB behaves like RIGHT
- •Use RIGHT to extract by character count instead of byte count
- •Mainly used in East Asian Excel installations
- •Using RIGHTB when RIGHT (character-based extraction) is actually what's needed - RIGHTB counts bytes, so a num_bytes value that seems right by character count can cut a double-byte character in half
- •Assuming num_bytes always corresponds directly to a whole number of characters - with double-byte text, an odd num_bytes value can split a single character, producing a garbled or unexpected result
- •Forgetting that on systems without double-byte character set support, RIGHTB simply behaves like RIGHT, so testing on a Western-locale machine can hide bugs that only appear with East Asian text
RIGHTExtracts by character count instead of byte count, the correct choice for text that doesn't need double-byte-aware handling.LEFTBPerforms the same byte-based extraction as RIGHTB but from the beginning of the string instead of the end.MIDBExtracts from any starting byte position, a more flexible version of the same byte-counting logic RIGHTB uses.Why did RIGHTB cut off part of a character instead of a clean substring?
num_bytes probably fell in the middle of a double-byte character counted from the end - since each such character occupies 2 bytes, an odd byte count can split one in half, producing a garbled result.
Should I use RIGHT or RIGHTB?
Use RIGHT for ordinary character-based extraction. Reach for RIGHTB only when you specifically need byte-based counting, such as matching a legacy system's storage limits for East Asian text.
Does RIGHTB work the same as RIGHT on a system without double-byte language support?
Yes, in that case there's no distinction between characters and bytes, so RIGHTB and RIGHT return identical results.
Need to translate a formula using RIGHTB?
Use our translator to convert your complete formula
