comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Converting INT to STRING out of space...

Re: Converting INT to STRING out of space...
type: item
description: Nuno Oliveira <nmoliveira@fc.ul.pt> writes: > If I want to save a file within a cicle and I want the name of > the file to have the number related to the cicle, I have a problem > that maybe someone in here have faced. > > Apparently there is no way that I can eliminate a space in a > string made of an integer variable. Try: > > number = 3 > aux = STRCOMPRESS(STRING(number)) > file = 'saving'+aux+'.dat' > > And, this way the variable file will be 'saving 3.dat' with a SPACE > inside the string. Any tips of how I can avoid this space? Yes, how about, aux = strtrim(number,2) or, to solve your whole problem at once, file = string(number,format='("saving",I0,".dat")') I use both. Craig -- ------------------------------------------------------------ -------------- Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response ------------------------------------------------------------ --------------
creator: Craig Markwardt
date: 2005-03-21T15:56:24-00:00

Re: Converting INT to STRING out of space...
type: item
description: Nuno Oliveira wrote: > If I want to save a file within a cicle and I want the name of the > file to have the number related to the cicle, I have a problem that > maybe someone in here have faced. > > Apparently there is no way that I can eliminate a space in a string > made of an integer variable. Try: > > number = 3 > aux = STRCOMPRESS(STRING(number)) > file = 'saving'+aux+'.dat' > > And, this way the variable file will be 'saving 3.dat' with a SPACE > inside the string. Any tips of how I can avoid this space? > > Greetings, > > Nuno > Try the /remove_all option in strcompress. Should do the trick. Regards, Tom McGlynn
creator: tam
date: 2005-03-21T16:00:15-00:00

Re: Converting INT to STRING out of space...
type: item
description: Nuno Oliveira wrote: > Apparently there is no way that I can eliminate a space in a string > made of an integer variable. Try: > > number = 3 > aux = STRCOMPRESS(STRING(number)) > file = 'saving'+aux+'.dat' > > And, this way the variable file will be 'saving 3.dat' with a SPACE > inside the string. Any tips of how I can avoid this space? I have a solution, but it isn't general. If you use: number = 3 aux = strtrim(string(number),2) file = 'saving' + aux + '.dat' It should solve your problem - by removing the space before it appears in the filename! The more general solution requires you to call the strcompress a bit later, and with the /remove_all keyword. number = 3 aux = string(number) file = strcompress('saving' + aux + '.dat', /remove_all) without /remove_all, strcompress compresses all whitespace to a single whitespace, it doesn't get rid of it. HTH, Ben -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Ben Panter, Garching, Germany email via www.benpanter.co.uk
creator: Ben Panter
date: 2005-03-21T16:00:30-00:00

Re: Converting INT to STRING out of space...
type: item
description: Ben Panter wrote: > Nuno Oliveira wrote: > >> Apparently there is no way that I can eliminate a space in a >> string made of an integer variable. Try: >> >> number = 3 >> aux = STRCOMPRESS(STRING(number)) >> file = 'saving'+aux+'.dat' > without /remove_all, strcompress compresses all whitespace to a single > whitespace, it doesn't get rid of it. hmmm. Alternativly if I were to engage my brain before posting, you could just put a /remove_all in your strcompress call, which would do the business. Ben -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Ben Panter, Garching, Germany email via www.benpanter.co.uk
creator: Ben Panter
date: 2005-03-21T16:03:10-00:00

Re: Converting INT to STRING out of space...
type: item
description: "Nuno Oliveira" <nmoliveira@fc.ul.pt> wrote in message news:d1mqh8$111t$1@pegasus.fccn.pt... > If I want to save a file within a cicle and I want the name of the file to > have the number related to the cicle, I have a problem that maybe someone > in here have faced. > > Apparently there is no way that I can eliminate a space in a string made > of an integer variable. Try: > > number = 3 > aux = STRCOMPRESS(STRING(number)) > file = 'saving'+aux+'.dat' > > And, this way the variable file will be 'saving 3.dat' with a SPACE inside > the string. Any tips of how I can avoid this space? > > Greetings, > > Nuno > The answers posted solve your problem for you. I would just add one tidbit, you can format the numbers to have leading 0's, so that they line up nicely when you get a file listing in alphabetical order. Use format of I3.3 for instance: string(number,format='("saving",I3.3,".dat")') Cheers, bob
creator: R.G. Stockwell
date: 2005-03-21T17:21:25-00:00