The MBCS inquiry routines provide information on the maximum length of multibyte characters, the length, number and position of multibyte characters in strings, and whether a multibyte character is a leading or trailing byte. These routines are summarized in the following table. The NLS library provides a parameter, MBLenMax, defined in the NLS module to be the longest length (in bytes) of any character, in any codepage. This parameter can be useful in comparisons and tests. To determine the maximum character length of the current codepage, use the MBCurMax function.
MBCS Inquiry Routines
Name | Procedure Type | Description |
---|---|---|
MBCharLen | Function | Returns the length of the first multibyte character in a string |
MBCurMax | Function | Returns the longest possible multibyte character for the current codepage |
MBLead | Function | Determines whether a given character is the first byte of a multibyte character |
MBLen | Function | Returns the number of multibyte characters in a string, including trailing spaces |
MBLen_Trim | Function | Returns the number of multibyte characters in a string, not including trailing spaces |
MBNext | Function | Returns the string position of the first byte of the multibyte character immediately after the given string position |
MBPrev | Function | Returns the string position of the first byte of the multibyte character immediately before the given string position |
MBStrLead | Function | Performs a context sensitive test to determine whether a given byte in a character string is a lead byte |
As an example:
USE DFNLS
CHARACTER(4) str
INTEGER status
status = NLSSetLocale ("Japan")
str = " ·, " ¿"
PRINT '(1X,''String by char = '',\)'
DO i = 1, len(str)
PRINT '(A2,\)',str(i:i)
END DO
PRINT '(/,1X,''MBLead = '',\)'
DO i = 1, len(str)
PRINT '(L2,\)',mblead(str(i:i))
END DO
PRINT '(/,1X,''String as whole = '',A,\)',str
PRINT '(/,1X,''MBStrLead = '',\)'
DO i = 1, len(str)
PRINT '(L1,\)',MBStrLead(str,i)
END DO
END
This code produces the following output for str = · , " ¿