string-->integer 
Author Message
 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

--




Wed, 18 Jun 1902 08:00:00 GMT  
 string-->integer

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?

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

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 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]);
ReadLn;
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

> --





Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. char/string -> integer

2. string --> integer

3. integer ----> char/string

4. Delphi>>>>>>>

5. Help (String to Integer)

6. Sql convert string to integer

7. integer to string conversion problem...

8. Showing a string for an integer field in DBGrid

9. read strings and integers from a file

10. Converting strings to integers

11. Validation for Integer, string and real....HELP!!!!

12. string to integer

 

 
Powered by phpBB® Forum Software