Delphi에서 확장된 문자열 조작 함수
3199 단어 Delphi
{***************************** *****************************}
procedure SwapStr(var s1, s2: string); //
function StrRight(Str: String; Len: Integer): String; // Examples: StrRight('ABCEDFG',3); :'DFG'
function StrLeft(Str: string; Len: Integer): string; //
function StrNum(ShortStr:string;LongString:string):Integer; //
function FindStr(ShortStr:String;LongStrIng:String):Integer; //
function SubStr(psInput:String; BeginPlace,CutLeng:Integer):String;// BeginPlace CatLeng
function RandomStr(aLength : Longint) : String; //
function RandomSys(Num: Integer): integer; //
function RandomGuid:string;// GUID
메소드 바디:
procedure SwapStr(var s1, s2: string);
var
tempstr: string;
begin
tempstr := s1;
s1 := s2;
s2 := tempstr;
end;
function StrRight(Str: string; Len: Integer): string;
begin
if Len >= Length(Str) then
Result := Str
else
Result := Copy(Str, Length(Str) - Len + 1, Len);
end;
function StrLeft(Str: string; Len: Integer): string;
begin
if Len >= Length(Str) then
Result := Str
else
Result := Copy(Str, 1, Len);
end;
function StrNum(ShortStr:string;LongString:string):Integer;
var
i:Integer;
begin
i:=0;
while pos(ShortStr,LongString)>0 do
begin
i:=i+1;
LongString:=Substr(LongString,(FindStr(ShortStr,LongString))+1,Length(LongString)-FindStr(ShortStr,LongString))
end;
Result:=i;
end;
function FindStr(ShortStr:String;LongStrIng:String):Integer;//
var
locality:integer;
begin
locality:=Pos(ShortStr,LongStrIng);
if locality=0 then
Result:=0
else
Result:=locality;
end;
function SubStr(psInput:String; BeginPlace,CutLeng:Integer):String;
begin
Result:=Copy(psInput,BeginPlace,CutLeng)
end;
function RandomStr(aLength : Longint) : String;
var
X : Longint;
begin
if aLength <= 0 then exit;
SetLength(Result, aLength);
for X:=1 to aLength do
Result[X] := Chr(Random(26) + 65);
end;
function RandomSys(Num: Integer): integer;
var
T: _SystemTime;
X: integer;
I: integer;
begin
Result := 0;
If Num = 0 then Exit;;
GetSystemTime(T);
X := Trunc(T.wMilliseconds/10) * T.wSecond * 1231;
X := X + random(1);
if X<>0 then
X := -X;
X := Random(X);
X := X mod num;
for I := 0 to X do
X := Random(Num);
Result := X;
end;
function RandomGuid:string;
var
ID: TGUID;
begin
if CreateGuid(ID) =0 then
begin
Result := GUIDToString(ID);
end;
end;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Delphi 목마 자기 복제법 구현목마가 자기 복사를 실현하는 원리는 프로그램이 실행될 때 먼저 자신이 특정 디렉터리에 있는지 확인하고 그렇지 않으면 계속 실행하며 그렇지 않으면 특정 디렉터리에 복사한 다음에 새로운 프로그램을 실행하고 낡은 프로그램...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.