PC Review


Reply
Thread Tools Rate Thread

Convert C# code to Delphi, please help!

 
 
mesutalturk@gmail.com
Guest
Posts: n/a
 
      25th Aug 2006
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[i];
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!

 
Reply With Quote
 
 
 
 
Noah Sham
Guest
Posts: n/a
 
      25th Aug 2006
How? ..learn object pascal

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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[i];
> 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!
>



 
Reply With Quote
 
Massuda
Guest
Posts: n/a
 
      25th Aug 2006

(E-Mail Removed) escreveu:

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


Try this online tool from Borland...

http://dotnet.borland.com/babelclient/BabelClient.aspx

 
Reply With Quote
 
chanmm
Guest
Posts: n/a
 
      26th Aug 2006
Make it a library class then call by Delphi so you might not need to
convert.

chanmm

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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[i];
> 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!
>



 
Reply With Quote
 
mesutalturk@gmail.com
Guest
Posts: n/a
 
      26th Aug 2006
this code could be convert or changing by me? help me please

 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      26th Aug 2006
(E-Mail Removed) wrote:

> 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[i];
> 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[i]));
Result := Result mod Cardinal(High(Integer)) + 1;
end;

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
mesutalturk@gmail.com
Guest
Posts: n/a
 
      26th Aug 2006
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.

 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      26th Aug 2006
(E-Mail Removed) wrote:

> 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:

> > > int upper = intc & '\x00df'; //Upper case the letter


.... 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[i]) and $DF;
Result := Result mod Cardinal(High(Integer)) + 1;
end;

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
mesutalturk@gmail.com
Guest
Posts: n/a
 
      26th Aug 2006
very thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert Delphi Record to C#? Magus Microsoft C# .NET 14 16th Mar 2010 12:29 AM
How to convert Delphi Record to C#? drilus Microsoft C# .NET 0 12th Mar 2010 03:41 PM
About Delphi Code Convert Vb.net darkjack Microsoft VB .NET 0 7th Feb 2010 09:36 AM
Convert from Delphi to C# Mel Weaver Microsoft C# .NET 2 9th Sep 2005 06:53 AM
Convert Delphi to C# Kostya Ergin Microsoft C# .NET 6 8th Jun 2005 09:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 AM.