convert string to int 
Author Message
 convert string to int

does anybody here know how to convert string to integer or integer to
string? i can not find the Pascal built-in function for this. your help is
very needed . thank you very much


Fri, 07 Mar 2003 03:00:00 GMT  
 convert string to int

Quote:

>does anybody here know how to convert string to integer or integer to
>string? i can not find the pascal built-in function for this. your help is
>very needed . thank you very much

String to+ integer Val()

Val(s,x,err);

where x is longint and err is integer. Err tells the position of the
error or zero if no error. While it compiles also when x is integer or
word, that is not recommended as it does not catch all errors. (to be
exact if the number is too big it will take the lowest word). Note there
cannot be leading or trailing spaces. Trim the string from those before
using val().

For number to string use str(),  Str(x,st); You can also use field
specifiers like you would use with write().

Btw this is for Turbo Pascal since you posted to Borland group. You
should not crosspost between the different Pascal groups. Use the group
only that is relevant to your compiler.

Osmo



Fri, 07 Mar 2003 03:00:00 GMT  
 convert string to int


Quote:
>does anybody here know how to convert string to integer or integer to
>string? i can not find the pascal built-in function for this. your help is
>very needed . thank you very much

Look up the Val and Str procedures
--
Information on Newsgroup posted weekly on Sunday - read before writing!
Contains links to    |  http://www.pedt.serve.net.uk/faq/clpb-faq.txt
helpful information  |  http://www.merlyn.demon.co.uk/clpb-faq.txt
and some guidelines  |  ftp://garbo.uwasa.fi/pc/doc-net/faqclpb.zip


Fri, 07 Mar 2003 03:00:00 GMT  
 convert string to int

Quote:

> does anybody here know how to convert string to integer or integer to
> string? i can not find the pascal built-in function for this. your help is
> very needed . thank you very much

If you are using Turbo/Borland Pascal or a Turbo/Borland Pascal
compatible compiler, use Val() for converting strings to integer and
str() for the reverse. I don't know whether these procedures are also
part of the ANSI (extended) Pascal standard, but I think they are.

Jonas



Sat, 08 Mar 2003 03:00:00 GMT  
 convert string to int

Quote:



> > does anybody here know how to convert string to integer or integer to
> > string? i can not find the pascal built-in function for this. your help is
> > very needed . thank you very much

> If you are using Turbo/Borland Pascal or a Turbo/Borland Pascal
> compatible compiler, use Val() for converting strings to integer and
> str() for the reverse. I don't know whether these procedures are also
> part of the ANSI (extended) Pascal standard, but I think they are.

Although ISO Pascal doesn't have equivalent built-in routines, you can
accomplish the conversion by using an anonomous text file.  Write the
string(integer) to the file then reset the file and read the opposite
integer(string).  (Keeping in mind that the string type in ISO Pascal
is a fixed length array of char.)

One of the capabilities ISO Extended Pascal added was built-in support
for variable length strings with the standard string schema type.
Included in the support are the required procedures readstr and
writestr which are equivalent to the file based read amd write
procedures.  With readstr and writestr you can easily perform
integer-to-string and string-to-integer conversions as well as
conversions type-to-string and string-to-type for all the other legal
parameter types.  A small example:

program StringConversionTest;

var

  TempStr : string(40);
  AnInt : integer value 0;
  AFloat : real value 0.0;

begin
  TempStr := '20';
  readstr(TempStr, AnInt);
  readstr('15.4e2', AFloat);
  writestr(TempStr, AFloat);
end.

Gale Paeper



Mon, 17 Mar 2003 09:04:51 GMT  
 convert string to int
It is also very easy to write a simpler parser.  Before I got Extended Pascal, I
wrote my own "ReadReal ()" routine, as the Pascal I was using had a bug in real
input for DOS.  An extra benefit is that I could recognize non-numeric input, and
give an error
message, asking the user to enter another number, rather than simply generating a
run time error.

Bob Schor

Quote:





> > > does anybody here know how to convert string to integer or integer to
> > > string? i can not find the pascal built-in function for this. your help is
> > > very needed . thank you very much

> > If you are using Turbo/Borland Pascal or a Turbo/Borland Pascal
> > compatible compiler, use Val() for converting strings to integer and
> > str() for the reverse. I don't know whether these procedures are also
> > part of the ANSI (extended) Pascal standard, but I think they are.

> Although ISO Pascal doesn't have equivalent built-in routines, you can
> accomplish the conversion by using an anonomous text file.  Write the
> string(integer) to the file then reset the file and read the opposite
> integer(string).  (Keeping in mind that the string type in ISO Pascal
> is a fixed length array of char.)

> One of the capabilities ISO Extended Pascal added was built-in support
> for variable length strings with the standard string schema type.
> Included in the support are the required procedures readstr and
> writestr which are equivalent to the file based read amd write
> procedures.  With readstr and writestr you can easily perform
> integer-to-string and string-to-integer conversions as well as
> conversions type-to-string and string-to-type for all the other legal
> parameter types.  A small example:

> program StringConversionTest;

> var

>   TempStr : string(40);
>   AnInt : integer value 0;
>   AFloat : real value 0.0;

> begin
>   TempStr := '20';
>   readstr(TempStr, AnInt);
>   readstr('15.4e2', AFloat);
>   writestr(TempStr, AFloat);
> end.

> Gale Paeper



Mon, 17 Mar 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. convert string to int

2. help on RANDOM and converting int's to strings

3. Converting Bytes(?) to Int / Int to Bytes

4. How to convert strings to nul-terminated strings?

5. Readln( file, char, char, string[10], int );

6. Converting strings for calculation

7. Converting string name to TEdit

8. Converting a string to an arithmatic operation

9. TP7: Converting String to Array of Char

10. how to convert byte to string?

11. Converting a Tmemo in a string ?

12. Sql convert string to integer

 

 
Powered by phpBB® Forum Software