Convert C# code to Delphi, please help!

  • Thread starter Thread starter mesutalturk
  • Start date Start date
M

mesutalturk

How do i convert the following C# code to Delphi?


public static uint GenerateSiteID(string SiteName)
{
uint id = 0;
char[] arr = SiteName.ToCharArray(); //Convert the sitename to a Char
Array
for (int i = 0; i < arr.Length; i++)
{
char c = arr;
int intc = c;
int upper = intc & '\x00df'; //Upper case the letter
id = (uint)(id * 101) + (uint)upper;
}
return (id % Int32.MaxValue) + 1; //do a MOD and add 1
}


Thanks for your help!
 
How do i convert the following C# code to Delphi?

public static uint GenerateSiteID(string SiteName)
{
uint id = 0;
char[] arr = SiteName.ToCharArray(); //Convert the sitename to a Char
Array
for (int i = 0; i < arr.Length; i++)
{
char c = arr;
int intc = c;
int upper = intc & '\x00df'; //Upper case the letter
id = (uint)(id * 101) + (uint)upper;
}
return (id % Int32.MaxValue) + 1; //do a MOD and add 1
}


function GenerateSiteID(const SiteName: string): Cardinal;
var
i: Integer;
begin
Result := 0;
for i := 1 to Length(SiteName) do
Result := Result * 101 + Ord(UpCase(SiteName));
Result := Result mod Cardinal(High(Integer)) + 1;
end;

-- Barry
 
thans for all your helps. but now its must to be giving this ritgh code
mubber is 1694692055 but its had give me code number is in the
mesedo.com like 1727991987 by them.. how can i do that.
 
thans for all your helps. but now its must to be giving this ritgh code
mubber is 1694692055 but its had give me code number is in the
mesedo.com like 1727991987 by them.. how can i do that.

Yes, I see that - the C# code:

.... does more than upper case the letter. It also modifies non-letters
like '.'. Instead:

function GenerateSiteId(const SiteName: string): Cardinal;
var
i: Integer;
begin
Result := 0;
for i := 1 to Length(SiteName) do
Result := Result * 101 + Ord(SiteName) and $DF;
Result := Result mod Cardinal(High(Integer)) + 1;
end;

-- Barry
 
Back
Top