pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: combining string values


From: Ben Pfaff
Subject: Re: combining string values
Date: Mon, 05 Jan 2009 10:39:34 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Jason Stover <address@hidden> writes:

> On Sun, Jan 04, 2009 at 01:10:16PM -0800, Ben Pfaff wrote:
>> Jason Stover <address@hidden> writes:
>> 
>> > I need to combine multiple string values into a single
>> > string, in a one-to-one way. For example, in the following
>> > data set, there are two variables, each with two values:
>> >
>> >    var1            var2
>> >    ae              f
>> >    a               ef
>> >
>> > I don't want to just concatenate the values because
>> > I would have aef in both cases.
>> 
>> If you strip the whitespace at the end of each string, this is
>> true.  If you retain the whitespace, then you have "aef " and "a
>> ef", which are of course different.
>
> Then what about this:
>
>      var1     var2
>      a e      f
>      a                e f
>
> If whitespace is allowed in a value, then we would concatenate to get
> "a e f " in both cases.

We're talking about data from PSPP variables, right?  PSPP
variables are always fixed-width.  If var1 is an A4 variable and
var2 is an A11 variable, then they would combine to form an A15
variable.  You'd get "a e f          " and "a           e f".

>> > I can work around this by using strtol, or something
>> > like it. 
>> 
>> I don't see how strtol is relevant?
>
> To avoid concatenating, I had been thinking of changing each string to
> an integer, then using a one-to-one function from the ordered
> n-tuples of integers to the integers.  For example, something like:
>
>       value  ae --> 1
>       value   f -->  2
>       value  aeu --> 87
>
> Then compute n := g (1,2,87), where g is some invertible function. I
> had planned to use strtol to map strings to integers. Maybe that's not
> the right way.

Well--not discussing this idea on its other merits--strtol will
only give you an interesting integer if the string value actually
starts with a number.  Otherwise it returns 0.

> But to take a step back: What is a good way to create a new union
> value from a list of other union values, that avoids collisions?
> Concatenate with some character other than whitespace?

I think that concatenation, without a delimiter, is sufficient.
Either that or I don't understand the whole problem yet.
-- 
"Term, holidays, term, holidays, till we leave school,
 and then work, work, work till we die."
C. S. Lewis




reply via email to

[Prev in Thread] Current Thread [Next in Thread]