14-11-2018, Saat: 10:18
Ben de değişik bir kaç metod yazdım. Onları paylaşayım:
GetData metodunda bazı güvenlik kontrolleri koydum, diğerlerine de ekleyip eklememek tamamen sizin tasarrufunuz.
function GetData(const ASource : String; const AStart, ALen : Integer) : String;
var
ASize,
AIndex : Integer;
begin
ASize := ALen;
AIndex:= AStart;
if ASource.IsEmpty then
Exit('');
if ASize <= 0 then
Exit('');
if ASize > ASource.Length then
ASize := ASource.Length;
if not AIndex in [1..ASize] then
AIndex := 1;
SetLength(Result, ASize);
Move(ASource[AIndex], Pointer(Result)^, ASize * SizeOf(Char));
end;
function FromRight(const ASource : String; const ALen : Integer) : String;
begin
Result := GetData(ASource, (ASource.Length - ALen) + 1, ALen);
end;
function FromLeft(const ASource : String; const ALen : Integer) : String;
begin
Result := GetData(ASource, 1, ALen);
end;
function FromRightEx(const ASource : String; const ALen : Integer) : String;
var
PCurrent,
PEnd,
PTarget : PChar;
begin
SetLength(Result, ALen);
PCurrent := @ASource[(ASource.Length - ALen) + 1];
PEnd := @ASource[ASource.Length];
PTarget := @Result[1];
while PCurrent <= PEnd do
begin
PTarget^ := PCurrent^;
Inc(PCurrent);
Inc(PTarget);
end;
end;
function FromLeftEx(const ASource : String; const ALen : Integer) : String;
var
PCurrent,
PEnd,
PTarget : PChar;
begin
SetLength(Result, ALen);
PCurrent := @ASource[1];
PEnd := @ASource[ALen];
PTarget := @Result[1];
while PCurrent <= PEnd do
begin
PTarget^ := PCurrent^;
Inc(PCurrent);
Inc(PTarget);
end;
end;
GetData metodunda bazı güvenlik kontrolleri koydum, diğerlerine de ekleyip eklememek tamamen sizin tasarrufunuz.
Mal sahibi, mülk sahibi
Hani bunun ilk sahibi ?
Mal da yalan mülk de yalan
Var biraz da sen oyalan...
Hani bunun ilk sahibi ?
Mal da yalan mülk de yalan
Var biraz da sen oyalan...

