Convert C# code to Delphi, please help!

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!
 
C

chanmm

Make it a library class then call by Delphi so you might not need to
convert.

chanmm
 
B

Barry Kelly

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
 
M

mesutalturk

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.
 
B

Barry Kelly

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top