bsp; else Msg := Msg + '''' is equal to '''' Msg := Msg + Edit2.Text; ShowMessage(Msg); end;
var S1,S2: PChar; I: Integer; Res: string; begin S1:= ''''ABC''''; S2:= ''''abc''''; I:= StrIComp(S1, S2); { I := 0, ?.?. S1 = S2 } if I>0 then Res:= ''''>'''' else if I<0 then Res:= ''''<'''' else Res:= ''''=''''; MessageDlg( S1 + Res + S2, mtInformation, [mbOk], 0); end; ----------------------------------------------------------------------------- StrLCat 字串相加.(指定长) ----------------------------------------------------------------------------- Unit SysUtils 函数原型 function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar; 范例 uses SysUtils; var S: array[0..13] of Char; begin StrLCopy(S, ''''Object'''', SizeOf(S) - 1); StrLCat(S, '''' '''', SizeOf(S) - 1); StrLCat(S, ''''Pascal'''', SizeOf(S) - 1); Canvas.TextOut(10, 10, StrPas(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 S1: PChar = ''''???''''; S2: PChar = ''''?????????''''; var S: array[0..13] of Char; begin StrLCopy(S, S1, StrLen(S1)); StrLCat(S, S2, 6); { S :=''''??????'''' } MessageDlg(S, mtInformation, [mbOk], 0); end; ## StrLen, StrLCat Example ----------------------------------------------------------------------------- StrLComp 比较两字串大小.(指定长) ----------------------------------------------------------------------------- Unit SysUtils 函数原型 function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer; 范例 uses SysUtils; const S1: PChar = ''''Enterprise'''' S2: PChar = ''''Enter'''' var Result: string; begin if StrLComp(S1, S2, 5) = 0 then Result := ''''equal'''' else Result := ''''different''''; Canvas.TextOut(10, 10, ''''The first five characters are '''' + Result); end; example uses SysUtils; const S1: PChar = ''''Enterprise'''' S2: PChar = ''''Enter'''' var ComStr: string; begin if StrLComp(S1, S2, 5) = 0 then ComStr := ''''equal'''' else ComStr := ''''different''''; Canvas.TextOut(10, 10, ''''The first five characters are '''' + ComStr); end; const S1: PChar = ''''?????????''''; S2: PChar = ''''????????''''; var I: Integer; S: string; begin I:= 5; if StrLComp( S1, S2, I) = 0 then S:= ''''?????'''' else S:= ''''????????''''; MessageDlg( ''''?????? ''''+ IntToStr(I)+ '''' ???????? ????? ''''+ S, mtInformation,[mbOk], 0); end;
----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- StrLIComp 比较两字串大小.(指定长,不分大小写) ----------------------------------------------------------------------------- Unit SysUtils 函数原型 function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinals): Integer; 范例 uses SysUtils; const S1: PChar = ''''Enterprise'''' S2: PChar = ''''Enter'''' var Result: string; begin if StrLIComp(S1, S2, 5) = 0 then Result := ''''equal'''' else Result := ''''different''''; Canvas.TextOut(10, 10, '' << 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >> |