# Board index » delphi » string-->integer

## string-->integer

Hi,

just a simple problem:

I want the user to put in a string, e.g. 3354G9HM3
Then I want to transform every single character into an in integer. For
example an 'A' is 10, 'B' is 11...'Z' is 35.

My first idea was to define an array[1..126]. With using the ord-function I
get an integer (e.g. A --> 65). which leads to the definition array[65] :=
10. Now the program knows that an 'A' is 10. But that didn't work. Is there
an other function to do this or at least a better way?

Greetings, Daniel

--
Daniel Knapp <dkn...@gmx.net>
Uni Rostock <daniel.kn...@informatik.uni-rostock.de>

## Re:string-->integer

In article <3a0549e...@news.uni-rostock.de>,

##### Quote
Serge Knapp <dkn...@gmx.net> wrote:
>Hi,

>just a simple problem:

>I want the user to put in a string, e.g. 3354G9HM3
>Then I want to transform every single character into an in integer. For
>example an 'A' is 10, 'B' is 11...'Z' is 35.

>My first idea was to define an array[1..126]. With using the ord-function I
>get an integer (e.g. A --> 65). which leads to the definition array[65] :=
>10. Now the program knows that an 'A' is 10. But that didn't work. Is there
>an other function to do this or at least a better way?

case ch of
'0'..'9': v:=ord(ch)-48
'A'..'Z': v:=ord(ch)-55;
else error;
End;

Osmo

## Re:string-->integer

Is the situation so simple that the value of each element in the array just
needs to be set?

Var
a: char;
ray: array[1..126] of integer;

Begin
ray[65]:= 10;
WriteLn(ray[Ord('A')]);
WriteLn(ray[65]);
End.

I usually take a different approach. Have an index string bb and loop
through the input string aa up to the length of aa. Then the POS function in
the loop finds the index string location of each element of aa. And a
defined array might still be needed.

##### Quote
> Hi,

> just a simple problem:

> I want the user to put in a string, e.g. 3354G9HM3
> Then I want to transform every single character into an in integer. For
> example an 'A' is 10, 'B' is 11...'Z' is 35.

> My first idea was to define an array[1..126]. With using the ord-function
I
> get an integer (e.g. A --> 65). which leads to the definition array[65] :=
> 10. Now the program knows that an 'A' is 10. But that didn't work. Is
there
> an other function to do this or at least a better way?

> Greetings, Daniel

> --
> Daniel Knapp <dkn...@gmx.net>
> Uni Rostock <daniel.kn...@informatik.uni-rostock.de>