comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: create string of fixed length
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: create string of fixed length [message #47874] Wed, 08 March 2006 06:43
Norbert Hahn is currently offline  Norbert Hahn
Messages: 46
Registered: May 2003
Member
justspam03@yahoo.de wrote:

> Hi,
>
> here's a probably very easy one (my apologies, but the help file failed
> to provide such)
> How does one create a string of fixed length, say a string consisting
> of 168 space
> characters?

There is no such beast as fixed length of string - if I'm not mistaken.
Surely I can assing 168 spaces to a variable of type string, but when
I execute abc = "*" some lines later, the length of the string abc
will change to one byte.

To maintain the original length and using my example I would have to
replace byte one with "*" in an assignment that may look like
strput, abc, "*", 1

... or am I completely wrong?

Norbert
Re: create string of fixed length [message #47879 is a reply to message #47874] Wed, 08 March 2006 01:55 Go to previous message
justspam03 is currently offline  justspam03
Messages: 36
Registered: October 2003
Member
Oj, I'm impressed. This is almost like
there's-more-than-one-way-to-do-it-Perl.
I think I like the replicate version best.
No, actually I like the
char *s = (char *) malloc(169 * sizeof(char));
for( i = 0; i < 168; i++ ) s[i] = ' '; s[168]='\0';
version best ;-)
Thanks!
O. (ducking away)
Re: create string of fixed length [message #47882 is a reply to message #47879] Wed, 08 March 2006 00:28 Go to previous message
mmeron is currently offline  mmeron
Messages: 44
Registered: October 2003
Member
In article <dum2em$kdo$1@dolly.uninett.no>, Jan Kristian Jensen <jankj11_nospam_remove_@_bluezone.no> writes:
> justspam03@yahoo.de wrote:
>> How does one create a string of fixed length, say a string consisting
>> of 168 space characters?
>
> And you could always apply brute force:
>
> space = ' '
> longspace = ''
> for i = 0, 167 do longspace = longspace + space
>
What's wrong with

longspace = string(replicate(32b,168))

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: create string of fixed length [message #47883 is a reply to message #47882] Tue, 07 March 2006 23:51 Go to previous message
Jan Kristian Jensen is currently offline  Jan Kristian Jensen
Messages: 10
Registered: February 2006
Junior Member
justspam03@yahoo.de wrote:
> How does one create a string of fixed length, say a string consisting
> of 168 space characters?

And you could always apply brute force:

space = ' '
longspace = ''
for i = 0, 167 do longspace = longspace + space


Jan
--
Jan Kristian Jensen

Remove the obvious from the email adress to email me.
Re: create string of fixed length [message #47889 is a reply to message #47883] Tue, 07 March 2006 17:04 Go to previous message
codepod is currently offline  codepod
Messages: 19
Registered: March 2006
Junior Member
Or there's the simple format trick:

cow = string(' ', format='(a168)')


justspam03@yahoo.de wrote:
> Hi,
>
> here's a probably very easy one (my apologies, but the help file failed
> to provide such)
> How does one create a string of fixed length, say a string consisting
> of 168 space
> characters?
> Thanks!
> Oliver
Re: create string of fixed length [message #47890 is a reply to message #47889] Tue, 07 March 2006 16:31 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
justspam03@yahoo.de writes:

> here's a probably very easy one (my apologies, but the help file failed
> to provide such)
> How does one create a string of fixed length, say a string consisting
> of 168 space

I'd do it just a little bit differently than Paul, but
it amounts to the same thing:

fixedStr = String(Replicate(32B, 168))

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: create string of fixed length [message #47891 is a reply to message #47890] Tue, 07 March 2006 16:07 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
justspam03@yahoo.de wrote:
> Hi,
>
> here's a probably very easy one (my apologies, but the help file failed
> to provide such)
> How does one create a string of fixed length, say a string consisting
> of 168 space
> characters?

How 'bout

spaces = MAKE_ARRAY( 168, VALUE=32B )

?

It's not quite a string per se, but mostly fulfills the same function.

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: About REGRESS.pro
Next Topic: Re: IDL Unix Color Problem

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:37:30 PDT 2025

Total time taken to generate the page: 0.00491 seconds