Answer the question
In order to leave comments, you need to log in
How to expand a string?
There is a string "4169BB8C", how to reverse it by 2 characters to get "8CBB6941"?
Answer the question
In order to leave comments, you need to log in
procedure TForm1.Button1Click(Sender: TObject);
var
st,st1:string;
i,l:integer;
begin
st:='4169BB8C'; // => 8CBB6941
l:=length(st);
st1:='';
i:=1;
repeat
st1:=st1+st[l-i]+st[l-i+1];
i:=i+2;
until i>=l;
Form1.Caption:=st+'=>'+st1;
end;
function RevertString(Value: String): String;
var
PValue, PResult, PStartValue: PChar;
LenValue: Integer;
begin
LenValue := Length(Value);
if LenValue mod 2 > 0 then raise Exception.Create('По 2 символа не получтися');
PValue := PChar(Value);
PStartValue := PValue;
SetLength(Result, LenValue);
PResult := PChar(Result);
Inc(PValue, LenValue - 2);
while PValue >= PStartValue do
begin
Move(PValue^, PResult^, 4);
Inc(PResult, 2);
Dec(PValue, 2);
end;
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question