[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: combining string values
From: |
Jason Stover |
Subject: |
Re: combining string values |
Date: |
Mon, 5 Jan 2009 14:17:21 -0500 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Mon, Jan 05, 2009 at 10:39:34AM -0800, Ben Pfaff wrote:
> 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".
Oh. Concatenation should work then.
> >> > 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.
Oh. Maybe I should have read that man page before assuming it did
something it doesn't do.
> > 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.
Then I'll use concatenation. If it breaks, I'll use something else.
-Jason