[Thread Prev][Thread Next][Index]

Re: [ferret_users] concatenating strings with integers



Hi Marco,

A workaround would be to simply truncate the final "." from the result
of FLOATSTR():

  NOAA/PMEL TMAP
  FERRET v6.95 (rc3)
  Linux 2.6.32-573.3.1.el6.x86_64 64-bit - 09/15/15
  18-Sep-15 12:26

yes? let First = { "one", "two", "three" }
yes? let Second= { 1, 2, 3 }
yes? let f = floatstr(Second,"(f0.0)")
yes? let n = strlen(f)
yes? let Third = First + substring(f, 1, n-1)
yes? list Third
             VARIABLE : FIRST + SUBSTRING(F, 1, N-1)
             SUBSET   : 3 points (X)
 1   / 1:"one1"
 2   / 2:"two2"
 3   / 3:"three3"

Now it'd be nice if we could just do:

yes? let Third = First + substring(f, 1, strlen(f)-1)

However, this inline version crashes Ferret (the Ferret developers are
aware of this bug; Ansley: Trac #2209).  So instead we have to define
intermediate variables, as above.

Cheers,

Andrew


On Fri, Sep 18, 2015 at 11:46 AM, Marco van Hulten
<marco.van-hulten@xxxxxxxxxxxx> wrote:
> Dear Ferret users,
>
> I'd like to concatenate an array of strings and an array of integers
> (that should be converted to strings).  Now I have:
>
> let First = { "one", "two", "three" }
> let Second= { 1, 2, 3 }
> let Third = First + Second
>
> That doesn't work, since the elements of Second must be converted to
> strings, e.g.:
>
> let Third = First + FloatStr(Second, "(f0.0)")
> yes? list Third
>              VARIABLE : FIRST + FLOATSTR(SECOND, "(f0.0)")
>              SUBSET   : 3 points (X)
>  1   / 1:"one1."
>  2   / 2:"two2."
>  3   / 3:"three3."
>
> Not quite.  I do not want the colon.  Of course, I shouldn't have used
> FloatStr().  I rather need a string to *integer* function, but I think
> that Ferret does not have that.
>
> Of course I could do anything by spawning awk(1), but a native Ferret
> solution would be more neat.
>
> I guess this is a feature request: and IntStr() function.
>
> Marco


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement