RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.StrEnd Function

Returns a pointer to the end of a null terminated string.

Pascal
function StrEnd(const Str: PAnsiChar): PAnsiChar; overload;
function StrEnd(const Str: PWideChar): PWideChar; overload;
C++
PAnsiChar StrEnd(const PAnsiChar Str);
PWideChar StrEnd(const PWideChar Str);

StrEnd returns a pointer to the null character at the end of Str.  

C++ Examples: 

 

/*
The following example uses an edit control, a label, and a
button on a form. When the button is clicked, the edit
control’s text is copied into a buffer. Then the buffer is
displayed backwards in the label.
*/

#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<char> pszEditText(new char[Edit1->Text.Length()+1]);
  char *psz;
  StrCopy(pszEditText.get(), Edit1->Text.t_str());
  psz = StrEnd(pszEditText.get());
  Label1->Caption = "";
  while (psz >= &pszEditText.get()[0])
  {
    psz--;
    Label1->Caption = Label1->Caption + *psz;
  }
}

 

Delphi Examples: 

{
The following example uses an edit control, a label, and a
button on a form. When the button is clicked, the edit
control’s text is copied into a buffer. Then the buffer is
displayed backwards in the label.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  TextBuffer: PChar;
  Ptr: PChar;
begin
  GetMem(TextBuffer, Length(Edit1.Text)+1);
  StrCopy(TextBuffer, PChar(Edit1.Text));
  Ptr := StrEnd(TextBuffer);
  Label1.Caption := '';
  while Ptr > TextBuffer do
  begin
    Dec(Ptr);
    Label1.Caption := Label1.Caption + Ptr^;
  end;
  FreeMem(TextBuffer);
end;

 

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