RAD Studio VCL Reference
SysUtils.CharToByteIndex Function

Returns the 1-based index of the first byte of a specified character in a string.

function CharToByteIndex(const S: AnsiString; Index: Integer): Integer; overload;
function CharToByteIndex(const S: UnicodeString; Index: Integer): Integer; overload;
int CharToByteIndex(const AnsiString S, int Index);
int CharToByteIndex(const UnicodeString S, int Index);

Call CharToByteIndex to obtain the byte offset for the character at a specified position in the string S, where 1 specifies the first character, 2 specifies the second character, and so on. CharToByteIndex returns zero if Index is out of range (Index <= 0 or S contains fewer than Index characters). If the Index parameter indicates a double-byte character, CharToByteIndex returns the offset of the first byte. 

If the system is not using a multi-byte character system (MBCS), CharToByteIndex returns the value of Index, because there is a 1:1 correspondence between bytes and characters. 


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!