473,813 Members | 3,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert C# code to Delphi, please help!

How do i convert the following C# code to Delphi?
public static uint GenerateSiteID( string SiteName)
{
uint id = 0;
char[] arr = SiteName.ToChar Array(); //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!

Aug 25 '06 #1
8 6675
How? ..learn object pascal

<me*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
How do i convert the following C# code to Delphi?
public static uint GenerateSiteID( string SiteName)
{
uint id = 0;
char[] arr = SiteName.ToChar Array(); //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!

Aug 25 '06 #2

me*********@gma il.com escreveu:
How do i convert the following C# code to Delphi?
Try this online tool from Borland...

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

Aug 25 '06 #3
Make it a library class then call by Delphi so you might not need to
convert.

chanmm

<me*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
How do i convert the following C# code to Delphi?
public static uint GenerateSiteID( string SiteName)
{
uint id = 0;
char[] arr = SiteName.ToChar Array(); //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!

Aug 26 '06 #4
this code could be convert or changing by me? help me please :(

Aug 26 '06 #5
me*********@gma il.com wrote:
How do i convert the following C# code to Delphi?

public static uint GenerateSiteID( string SiteName)
{
uint id = 0;
char[] arr = SiteName.ToChar Array(); //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(Site Name[i]));
Result := Result mod Cardinal(High(I nteger)) + 1;
end;

-- Barry

--
http://barrkel.blogspot.com/
Aug 26 '06 #6
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.

Aug 26 '06 #7
me*********@gma il.com 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(I nteger)) + 1;
end;

-- Barry

--
http://barrkel.blogspot.com/
Aug 26 '06 #8
very thanks. :)

Aug 26 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
13476
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
4
5395
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
0
1687
by: W. D. | last post by:
Hi Folks, My Delphi is rusty, and my C is corroded. Am I understanding this properly? CPP Code: TMainForm *MainForm Is this a declaration for a form named 'MainForm'
2
3675
by: Peter Williams | last post by:
Hi All, I need to port the following (small) C language function to Delphi: double Rand(void) { return rand()/(1.0 + (double)RAND_MAX); } NB -- elsewhere in the program randomize is called before-hand.
11
17422
by: Kai Bohli | last post by:
Hi all ! I need to translate a string to Ascii and return a string again. The code below dosen't work for Ascii (Superset) codes above 127. Any help are greatly appreciated. protected internal string StringToAscii(string S) { byte strArray = Encoding.UTF7.GetBytes(S); string NewString = Encoding.UTF7.GetString(strArray);
1
3692
by: Peter Williams | last post by:
Hello All, I'm a newbie to this ng. I'm posting here because I have a question about debugging some javascript on some pages of my website. Please don't call me a "troll" -- because I'm not one. :-))) The next page is called "basic_snake" and creates a message which follows the cursor. Up until today, I used this type of message attached to the mouse pointer for the following pages on my website: index.html, delphi.html &...
52
1565
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly.
3
1384
by: bolega | last post by:
On Aug 21, 5:12 pm, gnuist...@gmail.com wrote: I got an email that rapidshar corporation is giving out many academic versions of delphi legally free. Please tell me which combination of version and book is best for learning. They must be consistent. I also need a link to the version for download, and install instructions. Thanks a lot that companies have finally become student friendly.
2
1891
by: nxumalob | last post by:
ProcAWDLookUp = function(hwndNotify: HWND; ulMsg: ULONG; fContainer: boolean; cObjectType: char; SearchCriteria: PSearchCriteria; usCount: USHORT; usSearchType: USHORT; pReserved: pointer): boolean; stdcall; FAWDLookUp: ProcAWDLookUp; FAWDLookUp:= GetProcAddress(FHandle, 'AwdApiLookup'); Result:= FAWDLookUp(0, 0, true, SearchType, @FCriteriaList, CriteriaCount, AWD_USE_SQL, nil); cheers
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10417
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9220
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4357
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.