substrb and MBCS

From: <>
Date: Mon, 4 Feb 2008 14:48:37 -0800 (PST)
Message-ID: <>

If one uses substrb on a MBCS string, will the returned result possibly include a "partial character" (i.e., only the leading byte or bytes of a multiple byte character), or does the function "trim" to the nearest whole character?

According to the documentation for RAISE_APPLICATION_ERROR, this function only takes 2048 *bytes* for an application defined error message. If I want to ensure that I don't exceed this, I'll simply substrb( message, 1, 2048 ), but the problem is that if substrb will split characters, then my resultant string may end with a different (or invalid) character code point (depending on my character set).

The only way I know to avoid this is to incrementally build the message string in a loop, character by character, and then test the length of the string after adding each character - the desired substring is obtained by either taking the entire source string (if the source string is exhausted before exceeding the 2048 byte threshold), or, once the 2048 byte threshold is exceeded in the destination string, removing the last character from that string. Since 32-bit characters are the longest character encodings (AFAIK), then I could optimize this slightly by starting with the substr( msg, 1, 512 ) as my initial destination string, and then build/test the string from there. Doable, yes, but UGLY!

Does anyone have any other ideas to deal with this?

  Mike Received on Mon Feb 04 2008 - 16:48:37 CST

Original text of this message