-----------------------------------------------------------------------------
StrLCopy 拷贝字串.(指定长)
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function StrLCopy(Dest, Source: PChar; MaxLen:
Cardinal): PChar;
范例 uses SysUtils;
var
S: array[0..11] of Char;
begin
StrLCopy(S, 'ObjectPascal', SizeOf(S) - 1);
Canvas.TextOut(10, 10, StrPas(S));
end;
Example
uses SysUtils;
const MAX_BUFFER = 10;
procedure TForm1.Button1Click(Sender TObject);
var
Buffer: array [0..MAX_BUFFER] of char;
begin
StrLCopy(Buffer, PChar(Edit1.Text), MAX_BUFFER);
Application.MessageBox(Buffer, 'StrLCopy Example', MB_OK);
end;
var
S: PChar;
begin
StrLCopy( S, '?????????', 5); { S := '?????' }
...
end;
-----------------------------------------------------------------------------
StrLen 传回字串长度.(不含终止位元)
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function StrLen(Str: PChar): Cardinal;
范例 uses SysUtils;
const
S: PChar = 'E Pluribus Unum';
begin
Canvas.TextOut(5, 10, 'The string length of "' + StrPas(S)
+ '" is ' + IntToStr(StrLen(S)));
end;
Example
procedure TForm1.Button1Click(Sender: TObject);
var
FirstHalf: PChar;
SecondHalf: PChar;
HalfLen: Integer;
begin
HalfLen := StrLen(PChar(Edit1.Text)) div 2;
GetMem(FirstHalf,HalfLen+2);
GetMem(SecondHalf,HalfLen+2);
FirstHalf^ := Chr(0);
SecondHalf^ := Chr(0);
StrLCat(FirstHalf, PChar(Edit1.Text), HalfLen);
StrCat(SecondHalf, PChar(Edit1.Text) + HalfLen);
Application.MessageBox(FirstHalf, 'First Half', MB_OK);
Application.MessageBox(SecondHalf, 'Second Half', MB_OK);
FreeMem(FirstHalf);
FreeMem(SecondHalf);
end;
const
S: PChar = '????? ????? ????? ????????!';
begin
MessageDlg( S+ #13#10 + '?????????? ???????? = ' + IntToStr( StrLen( S)), mtInformation, [mbOk], 0);
end;
## StrLen, StrLCat Example
StrLCopy 拷贝字串.(指定长)
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function StrLCopy(Dest, Source: PChar; MaxLen:
Cardinal): PChar;
范例 uses SysUtils;
var
S: array[0..11] of Char;
begin
StrLCopy(S, 'ObjectPascal', SizeOf(S) - 1);
Canvas.TextOut(10, 10, StrPas(S));
end;
Example
uses SysUtils;
const MAX_BUFFER = 10;
procedure TForm1.Button1Click(Sender TObject);
var
Buffer: array [0..MAX_BUFFER] of char;
begin
StrLCopy(Buffer, PChar(Edit1.Text), MAX_BUFFER);
Application.MessageBox(Buffer, 'StrLCopy Example', MB_OK);
end;
var
S: PChar;
begin
StrLCopy( S, '?????????', 5); { S := '?????' }
...
end;
-----------------------------------------------------------------------------
StrLen 传回字串长度.(不含终止位元)
-----------------------------------------------------------------------------
Unit SysUtils
函数原型 function StrLen(Str: PChar): Cardinal;
范例 uses SysUtils;
const
S: PChar = 'E Pluribus Unum';
begin
Canvas.TextOut(5, 10, 'The string length of "' + StrPas(S)
+ '" is ' + IntToStr(StrLen(S)));
end;
Example
procedure TForm1.Button1Click(Sender: TObject);
var
FirstHalf: PChar;
SecondHalf: PChar;
HalfLen: Integer;
begin
HalfLen := StrLen(PChar(Edit1.Text)) div 2;
GetMem(FirstHalf,HalfLen+2);
GetMem(SecondHalf,HalfLen+2);
FirstHalf^ := Chr(0);
SecondHalf^ := Chr(0);
StrLCat(FirstHalf, PChar(Edit1.Text), HalfLen);
StrCat(SecondHalf, PChar(Edit1.Text) + HalfLen);
Application.MessageBox(FirstHalf, 'First Half', MB_OK);
Application.MessageBox(SecondHalf, 'Second Half', MB_OK);
FreeMem(FirstHalf);
FreeMem(SecondHalf);
end;
const
S: PChar = '????? ????? ????? ????????!';
begin
MessageDlg( S+ #13#10 + '?????????? ???????? = ' + IntToStr( StrLen( S)), mtInformation, [mbOk], 0);
end;
## StrLen, StrLCat Example
情人太累,小姐太贵,友谊交往最实惠 ,没事开开“同学会”,拆散一对算一对!