Henry Olive 5 Posted September 14 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
Uwe Raabe 2064 Posted September 14 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
Henry Olive 5 Posted September 14 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
Kas Ob. 124 Posted September 14 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
Uwe Raabe 2064 Posted September 14 Ord returns the ordinal value of the character, not its position in the alphabet. Share this post Link to post
Henry Olive 5 Posted September 14 Thank you so much Kas, Uwe My problem solved. Share this post Link to post