[comp.lang.icon] concat with blank and a question

cargo@TARDIS.CRAY.COM (David S. Cargo) (01/19/90)

I recently purchased a product called HyperPAD for the PC.  It is intended
to be a HyperCard-like product for the PC.  What I found interesting was
something in its list of operators.  To concatenate two strings there is
the concatenation operator &.  However, there is an operator to concatenate
two strings with a space in between them, the && operator.  I realized that
this one little feature was a a nice convenience.  I know I have often used
something like  a || " " || b because I needed to put a space between two
strings I was combining.  Maybe from an overall language viewpoint this isn't
a significant improvement, but I thought it was an interesting addition to
a language with string processing.

The question I have is:  What is the best way to elminate spaces (or, to
generalize, members of a particular cset) from a string while still preserving
the order of the remaining characters?  I'm going to be performing some comparisons
where certain characters are very likely to not be significant.  I'm looking for
an efficient way of doing preprocessing to remove the insignificant characters.

                         o       o
                          \_____/
                          /-o-o-\     _______
DDDD      SSSS   CCCC    /   ^   \   /\\\\\\\\
D   D    S      C        \ \___/ /  /\   ___  \
D   D     SSS   C         \_   _/  /\   /\\\\  \
D   D        S  C           \  \__/\   /\ @_/  /
DDDDavid SSSS.   CCCCargo    \____\____\______/ CARGO@TARDIS.CRAY.COM

tenaglia@mis.mcw.edu (Chris Tenaglia - 257-8765) (01/20/90)

In reply to the concat,...

If you are running ICON under unix, and are adventurous, you can build
in your own concat with the 'Personal Interpretor' or 'Variant Translator'.
I've built a personal code library of icon software chips which I just
include using the editor when I use them.

Having an operator $ for example may accomplish :

  both := first $ second   (rather then both := first || " " || second)     

But it still not as flexible as a procedure :

  procedure cat(s1,s2,s3)
    /s3 := " "             # where an optional string may or may not appear.
    return s1 || s3 || s2
    end

---------------------------------------------------

Concerning Character Elimination in a String

This is best done with the string scanning feature of ICON. I'll present
a little procedure. Others may approach the problem differently.

  procedure strip(str,chrs)
    local text,chars
    /chrs := ' '
    chars := &cset -- chrs
    text  := ""
    str ? while tab(upto(chars)) do text ||:= tab(many(chars))
    return text
    end

Yours truly,

Chris Tenaglia (System Manager)
Medical College of Wisconsin
8701 W. Watertown Plank Rd.
Milwaukee, WI 53226
(414)257-8765
tenaglia@mis.mcw.edu