Board index » delphi » integer ----> char/string

integer ----> char/string

How do i convert an integer to a char of string?

mAze..

--
"I hate to advocate {*word*110}, {*word*63}, {*word*267}, or insanity to anyone, but
they've always worked for me."
Hunter S. Thompson.

 

Re:integer ----> char/string


Re:integer ----> char/string


i Mean Integer ------> Char OR String...

mAze..

Re:integer ----> char/string


In article <95jok7$gn...@news.kolumbus.fi>,

Quote
Maze <janne.kro...@kolumbus.fi> wrote:
>i Mean Integer ------> Char OR String...

To string Str(x,st);

To char: ch:=chr(x+48)

In the latter the value has to be 0..9, in the former any can do. You
can also use field specifiers with str() just as you use then with
write().

Osmo

Re:integer ----> char/string


On 4 Feb 2001 15:41:49 GMT, ronka...@cc.helsinki.fi (Osmo Ronkanen)
wrote:

Quote
>In article <95jok7$gn...@news.kolumbus.fi>,
>Maze <janne.kro...@kolumbus.fi> wrote:
>>i Mean Integer ------> Char OR String...

>To string Str(x,st);

>To char: ch:=chr(x+48)

>In the latter the value has to be 0..9, in the former any can do. You
>can also use field specifiers with str() just as you use then with
>write().

This assumes the ASCII charater numbering (admittedly a pretty safe
assumption with the Borland dialects); and it's also something of a
"magic number", if one doesn't know what's going on that 48 seems to
come out of nowhere.

Anyways, my generic/cross-platform sensibilities would insist on
something more like:

  ch := Chr(x + Ord('0'));

Since Ord() is reconciled at compile time you don't lose any run-time
benefits of using an integer; and this is arguably more
self-documenting.

Stephen Posey
slpo...@concentric.net

Other Threads