Board index » delphi » integer to string conversion problem...

integer to string conversion problem...

Hi !

I keep running into this kind of problems:

I want to do some modifications on a textfile, for example:

original.txt -> modify and save as -> original.1
original.1 -> modify and save as -> original.2
original.2 -> modify and save as -> original.3
etc...

So I need to convert my integer counter value into a string that is usable
as extension for the files... So after round 999 of modification I want the
extension to be .999

Does someone have a simple solution before I start doing this the not
so nice way with a large array of strings ranging from '1' to '999' !?

Regards,

Stephan

 

Re:integer to string conversion problem...


Quote
"-" <du...@wanadoo.nl> wrote:
>So I need to convert my integer counter value into a string that is usable
>as extension for the files...

var x : integer;
    s : string;

 str( x, s);

s is now a string for x.  

Re:integer to string conversion problem...


Sure. Use FSplit to get the file extension, Val to convert it to numeric,
add one and use Str to convert it back again. Now paste that new extension
onto the filename and there you are. Don't forget sanity checks at the
obvious points. (Extension numeric? Less than 999? etc)

Regards,
--
Jos van Kan
http://ta.twi.tudelft.nl/users/vankan

Quote
"-" <du...@wanadoo.nl> wrote in message

news:3b1813fe$0$82817@news2.zeelandnet.nl...
Quote
> Hi !

> I keep running into this kind of problems:

> I want to do some modifications on a textfile, for example:

> original.txt -> modify and save as -> original.1
> original.1 -> modify and save as -> original.2
> original.2 -> modify and save as -> original.3
> etc...

> So I need to convert my integer counter value into a string that is usable
> as extension for the files... So after round 999 of modification I want
the
> extension to be .999

> Does someone have a simple solution before I start doing this the not
> so nice way with a large array of strings ranging from '1' to '999' !?

> Regards,

> Stephan

Re:integer to string conversion problem...


Re:integer to string conversion problem...


I've got things working now...
I always overlooked the val and str functions in the help index.
But I kinda expected that there was some easier way for me
to get these things done.
Thanks for pointing me in the right direction !

Stephan

Re:integer to string conversion problem...


Re:integer to string conversion problem...


Something you might consider is to use leading zeros, i.e. say "filename.001",
"filename.002", etc. instead of "filename.1".  The reason for this is that it
will more logically sort on the extensions (i.e. file 2 will come before, not
after, files 10, 100, 199, etc.).

P.S. -- I've implemented such a numbering scheme several times, the first few
using single-digit numbers before I "wised up" to using 3 digits ...

Bob Schor
Pascal Enthusiast

Quote
- wrote:
> Hi !

> I keep running into this kind of problems:

> I want to do some modifications on a textfile, for example:

> original.txt -> modify and save as -> original.1
> original.1 -> modify and save as -> original.2
> original.2 -> modify and save as -> original.3
> etc...

> So I need to convert my integer counter value into a string that is usable
> as extension for the files... So after round 999 of modification I want the
> extension to be .999

> Does someone have a simple solution before I start doing this the not
> so nice way with a large array of strings ranging from '1' to '999' !?

> Regards,

> Stephan

Other Threads