Jump to content

Recommended Posts

Good Day

 

I'm trying to get a char's alphabetic order number

for example  A=1,  C=3... etc.

 

Edit2.Text := IntToStr(Ord(Edit1.Text));

with above code I'm getting  37331868 for A (expecting 1)

what am i doing wrong ?

 

Thank You

Share this post


Link to post

Edit1.Text is a string, which internally is a pointer. So Ord returns the value of the pointer.

 

Better identify the char you are interested in: Ord(Edit1.Text[1]);

Share this post


Link to post

Thank you so much Uwe, your code works but the result is not as my expectation

 

//Edit1.Text = A

Edit2.Text := IntToStr(Ord(Edit1.Text[1]));    Result = 65,  Expecting 1

 

//Edit1.Text = B

Edit2.Text := IntToStr(Ord(Edit1.Text[1]));    Result = 66,  Expecting 2

 

 

 

 

Share this post


Link to post
7 minutes ago, Henry Olive said:

//Edit1.Text = A

Edit2.Text := IntToStr(Ord(Edit1.Text[1]));    Result = 65,  Expecting 1

 

//Edit1.Text = B

Edit2.Text := IntToStr(Ord(Edit1.Text[1]));    Result = 66,  Expecting 2

If you have capital Latin letters then just subtract 64.

In case of small Latin letters then subtract 96.

 

https://en.wikipedia.org/wiki/ASCII

Share this post


Link to post

Ord returns the ordinal value of the character, not its position in the alphabet.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×