1

How can i convert string character (123-jhk25) to ASCII in Delphi7

1
  • 2
    the string '(123-jhk25)' in Delphi 7 containes only ASCII characters. No conversion required. Commented Feb 21, 2010 at 15:05

2 Answers 2

4

If you mean the ASCII code for the character you need to use the Ord() function which returns the Ordinal value of any "enumerable" type

In this case it works on character values, returning a byte:

var Asc : Byte; i : Integer; begin for i := 1 to Length(s) do begin Asc := Ord(s[i]); // do something with Asc end; end; 
Sign up to request clarification or add additional context in comments.

1 Comment

Worth pointing out that Chr(X) returns the AnsiChar of that ordinal value i.e. Chr(A) = "A" and X = Ord(Chr(X)) (assuming "X" is in the range of ASCII characters).
2

It depends on your Delphi version. In Delphi 2007 and before, strings are automatically in ANSI string format, and anything below 128 is an ASCII character.

In D2009 and later, things become more complicated since the default string type is UnicodeString. You'll have to cast the character to AnsiChar. It'll perform a codepage conversion, and then whatever you end up with may or may not work depending on which language the character in question came from. But if it was originally an ASCII character, it should convert without trouble.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.