[Lazarus] How can I increment/decrement a alphanumeric value?

bobby spasic at gmail.com
Fri Aug 20 05:47:31 CEST 2010


  On 8/20/2010 5:01 AM, silvioprog wrote:
>  Em 19/08/2010 17:26, bobby escreveu:
>> Hi,
>>
>> I have a function for increasing HEX values, based on string 
>> manipulations, not on conversion to integer and back.
>> Would that be of any help?
>>
>> bobby 
>
> Hi bobby,
>
> Would you show me the function?
>

Hi,

here it is:

function incHexStr(inHexStr: string): string;
var
   HexMap: string;
   i: integer;
   j: integer;
   s: string;
   carry: integer;
begin
   result := '';
   s := '';
   carry := 0;
   HexMap := '0123456789abcdef0123456789abcdef';

   for j := 1 to 16 do
     if AnsiLowerCase(inHexStr[length(inHexStr)]) = HexMap[j] then
     begin
       if j > 15 then carry := 1;
       inHexStr[length(inHexStr)] := HexMap[(j + 1)];
       break;
     end;
   if carry = 1 then
     for i := (length(inHexStr) - 1) downto 1 do
     begin
       if carry = 1 then
         for j := 1 to 16 do
           if AnsiLowerCase(inHexStr[i]) = HexMap[j] then
           begin
             carry := 0;
             if j > 15 then carry := 1;
             inHexStr[i] := HexMap[(j + 1)];
             break;
           end;
     end;
   if carry = 1 then inHexStr := '01' + inHexStr;
   result := inHexStr;
end;





More information about the Lazarus mailing list