[Thread Prev][Thread Next][Index]

Re: [ferret_users] concatenating strings with integers

Hi Marco,

I frequently create this type of strings inside a loop:

let First = xsequence({ "one", "two", "three" })
let Second= xsequence({ 1, 2, 3 })

repeat/i=1:`First,ret=iend` ( let Third = "`First`_`Second,zf=2`" )

I don't now how do it outside the loop, but using your idea you can reach the result using:

let tmp = floatstr(second,"(f0.0)")
let tmpl = strlen(tmp)-1
let third = substring(tmp,1,tmpl)

... not neat, but works...

On Fri, 2015-09-18 at 17:46 +0200, Marco van Hulten 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.


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

Privacy Policy | Disclaimer | Accessibility Statement