Examples Delphi

On Tue, 24 Oct 2000, Computer Solutions:AZ wrote:
> If vPChar is the value, and vString is the variable to hold the trimmed
> result, just do vString := Trim(vPChar). Delphi automatically converts the
> PChar to a wide string when it performs this operation. If you need to, you
> can then do vPChar := PChar(vString). vPChar := PChar(Trim(vPChar)) might
> work although I haven't tried it.
Use the StrPCopy function instead of an assignment if vPChar is pointing
to dynamically-allocaed (GetMem, StrAlloc, etc.) memory. Using an
assignment statement will not work when you need to do further
modifications to the memory area.
Another option may be to use the StrTrim function from the Windows API.
It's probably not declared in the Delphi units, but you can declare it
yourself as follows:
function StrTrim(pszSource: PChar; pszTrimChars: PChar): BOOL;
external 'shlwapi.dll' name 'StrTrimA';
function StrTrimA(pszSource: PAnsiChar; pszTrimChars: PAnsiChar): BOOL;
external 'shlwapi.dll';
function StrTrimW(pszSource: PWideChar; pszTrimChars: PWideChar): BOOL;
external 'shlwapi.dll';
This trims the characters in TrimChars off the start and end of Source in
place. Of course, it won't work if you want to preserve leading spaces.
--Rob
_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://elists.org/mailman/listinfo/delphi