Recent

Author Topic: [SOLVED] Convert String to ASCII code as Integer  (Read 23514 times)

RobWitcher

  • New Member
  • *
  • Posts: 31
Re: [SOLVED] Convert String to ASCII code as Integer
« Reply #15 on: April 16, 2013, 10:54:20 pm »
... and, if you want to get code of char by char, you can use a small code like:

Code: [Select]
var
  C: Char;
  S: string;
begin
  S := 'SomeString';
  for C in S do
    WriteLn(IntToStr(Ord(C)));
end;

PS1: sorry for my englysh plz.
PS2: I love Free Pascal. S2

Great. Don't worry, your English was pretty much fine.  :)
-Rob

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: Convert String to ASCII code as Integer
« Reply #16 on: April 16, 2013, 11:22:47 pm »
Ah, OK. :)

So you can:

Code: [Select]
var
  S: string;
begin
  S := 'A';
  Write(IntToStr(Ord(S[1])));
end;

Thank you so much...
...I don't suppose you know what the
Quote
[1]
does? I've never seen that before.
Interesting.
It's common knowledge that the individual characters of a string can be accessed via array subscription, but apparently this code construct is not documented in the reference guide.
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8814
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [SOLVED] Convert String to ASCII code as Integer
« Reply #17 on: April 17, 2013, 02:06:54 am »
Quote
It's common knowledge that the individual characters of a string can be accessed via array subscription, but apparently this code construct is not documented in the reference guide.
Good finding (not everyone come from a language with indexable strings), please report to the bugtracker.

 

TinyPortal © 2005-2018