Pascal Tips Homepage  •  Privacy Policy & Imprint

FreePascal Unit SysUtils

PChar Related Functions

Reference of the PChar (null-terminated string) functions from the SysUtils unit, section PChar Related Functions.

Most of these functions are identical to their counterparts in the Strings unit (green). A smaller set behaves differently from the Strings unit and is specific to SysUtils (orange) — most notably StrAlloc, which is not binary-compatible with the Strings unit's StrAlloc. Every function name links to its original documentation page.

Same as in the Strings unit

StrCat

function strcat(dest: pchar; source: pchar): pchar;
function strcat(dest: pwidechar; source: pwidechar): pwidechar;

Appends the null-terminated string Source to the end of Dest and returns Dest; no length checking is performed, so Dest must have enough room to hold the combined result.

StrComp

function strcomp(str1: pchar; str2: pchar): SizeInt;
function strcomp(str1: pwidechar; str2: pwidechar): SizeInt;

Compares the null-terminated strings Str1 and Str2 case-sensitively, returning a negative value if Str1 < Str2, zero if they are equal, and a positive value if Str1 > Str2.

StrCopy

function strcopy(dest: pchar; source: pchar): pchar; overload;
function StrCopy(Dest: PWideChar; Source: PWideChar): PWideChar; overload;

Copies the null-terminated string Source to Dest and returns Dest; Dest must have room for StrLen(Source)+1 bytes, since no length checking is performed.

StrECopy

function strecopy(dest: pchar; source: pchar): pchar;
function strecopy(dest: pwidechar; source: pwidechar): pwidechar;

Copies the null-terminated string Source to Dest, like StrCopy, but returns a pointer to the terminating null character at the end of the copy rather than to its start.

StrEnd

function strend(p: pchar): pchar;
function strend(p: pwidechar): pwidechar;

Returns a pointer to the terminating null character of the null-terminated string P, i.e. to its end.

StrIComp

function stricomp(str1: pchar; str2: pchar): SizeInt;
function stricomp(str1: pwidechar; str2: pwidechar): SizeInt;

Compares the null-terminated strings Str1 and Str2 case-insensitively, returning a negative value if Str1 < Str2, zero if they are equal, and a positive value if Str1 > Str2.

StrLCat

function strlcat(dest: pchar; source: pchar; l: SizeInt): pchar;
function strlcat(dest: pwidechar; source: pwidechar; l: SizeInt): pwidechar;

Appends at most L characters from Source to the end of Dest, adds a terminating null character, and returns Dest.

StrLComp

function strlcomp(str1: pchar; str2: pchar; l: SizeInt): SizeInt;
function strlcomp(str1: pwidechar; str2: pwidechar; l: SizeInt): SizeInt;

Compares at most L characters of the null-terminated strings Str1 and Str2 case-sensitively, returning a negative, zero, or positive value depending on their relative order.

StrLCopy

function strlcopy(dest: pchar; source: pchar; maxlen: SizeInt): pchar; overload;
function StrLCopy(Dest: PWideChar; Source: PWideChar; MaxLen: SizeInt): PWideChar; overload;

Copies at most MaxLen characters from Source to Dest and null-terminates the result; no length checking is performed against the actual size of Dest's buffer.

StrLen

function strlen(p: pchar): sizeint; overload;
function StrLen(p: pwidechar): sizeint; overload;

Returns the length of the null-terminated string P (excluding the terminating null character); returns 0 if P is Nil.

StrLIComp

function strlicomp(str1: pchar; str2: pchar; l: SizeInt): SizeInt;
function strlicomp(str1: pwidechar; str2: pwidechar; l: SizeInt): SizeInt;

Compares at most L characters of the null-terminated strings Str1 and Str2 case-insensitively, returning a negative, zero, or positive value depending on their relative order.

StrLower

function strlower(p: pchar): pchar;
function strlower(p: pwidechar): pwidechar;

Converts the null-terminated string P to all-lowercase in place and returns P.

StrMove

function strmove(dest: pchar; source: pchar; l: SizeInt): pchar; overload;
function StrMove(dest: PWideChar; source: PWideChar; l: SizeInt): PWideChar; overload;

Copies L characters from Source to Dest without appending a terminating null character, and returns Dest; unlike StrCopy/StrLCopy this is a raw character move, not a null-terminated-string copy.

StrNew

function strnew(p: pchar): pchar; overload;
function strnew(p: PWideChar): PWideChar; overload;

Allocates a copy of the null-terminated string P on the heap and returns a pointer to the copy; returns Nil if no memory was available.

StrPos

function strpos(str1: pchar; str2: pchar): pchar;
function strpos(str1: pwidechar; str2: pwidechar): pwidechar;

Returns a pointer to the first occurrence of the null-terminated string Str2 within Str1, or Nil if Str2 does not occur in Str1.

StrRScan

function strrscan(p: pchar; c: Char): pchar;
function strrscan(p: pwidechar; c: WideChar): pwidechar;

Returns a pointer to the last occurrence of the character C within the null-terminated string P, or Nil if C does not occur.

StrScan

function strscan(p: pchar; c: Char): pchar; overload;
function StrScan(P: PWideChar; C: WideChar): PWideChar; overload;

Returns a pointer to the first occurrence of the character C within the null-terminated string P, or Nil if C does not occur.

StrUpper

function strupper(p: pchar): pchar;
function strupper(p: pwidechar): pwidechar;

Converts the null-terminated string P to all-uppercase in place and returns P.

Different from the Strings unit (SysUtils-specific)

StrAlloc

function StrAlloc(Size: Cardinal): PChar;

Reserves heap memory for a null-terminated string of Size bytes (including the terminating #0) and returns a pointer to it; it additionally allocates 4 extra bytes to store the buffer's size, which makes it binary incompatible with the StrAlloc function of the Strings unit.

StrBufSize

function StrBufSize(Str: PChar): Cardinal;
function StrBufSize(str: pwidechar): Cardinal;

Returns the size, in bytes, of the heap memory allocated for Str; this only gives a correct result if Str was allocated with StrAlloc.

StrDispose

procedure StrDispose(Str: PChar);
procedure StrDispose(str: pwidechar);

Frees the heap memory allocated for Str; this only works correctly if Str was allocated on the heap via StrAlloc or StrNew, and passing an invalid or differently-allocated pointer may cause an error.

StrPCopy

function StrPCopy(Dest: PChar; const Source: string): PChar; overload;
function StrPCopy(Dest: PWideChar; const Source: UnicodeString): PWideChar; overload;

Converts the (Ansi)string in Source to a null-terminated string and copies it into Dest, which needs room for Length(Source)+1 bytes; no bounds checking is performed.

StrPLCopy

function StrPLCopy(Dest: PChar; const Source: string; MaxLen: SizeUInt): PChar; overload;
function StrPLCopy(Dest: PWideChar; const Source: UnicodeString; MaxLen: SizeUInt): PWideChar; overload;

Converts at most MaxLen characters of the string in Source to a null-terminated string and copies them into Dest; no checking is performed to ensure Dest has enough room.

StrPas

function StrPas(Str: PChar): string; overload;
function StrPas(Str: PWideChar): UnicodeString; overload;

Converts the null-terminated string Str into an Ansistring (or UnicodeString for the PWideChar overload) and returns it; unlike the System unit's version, the result is not truncated at 255 characters.


Other routines in SysUtils: File Name Handling Routines, File Input/Output Routines, Date/Time Routines, Conversion Routines, String Functions, Formatting Strings, PChar Related Functions.