Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7952
| From | Adriano Pascoletti <adriano.pascoletti@uniud.it> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Question about DeleteCases to remove list elements based on first character |
| Date | 2012-01-17 10:58 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jf3k8a$q6g$1@smc.vnet.net> (permalink) |
In[6]:= S = {"abc", ";def", "ghi", ";jkl", "; mno", "pqr;X"};
DeleteCases[S, s_ /; StringTake[s, 1] === ";"]
Select[S, StringTake[#1, 1] =!= ";" & ]
Out[7]= {"abc", "ghi", "pqr;X"}
Out[8]= {"abc", "ghi", "pqr;X"}
Adriano Pascoletti
2012/1/16 Andrew DeYoung <adeyoung@andrew.cmu.edu>
> Hi,
>
> I have a list of strings in which some elements begin with the ";"
> character and some do not. The ";" character indicates a program
> comment, so I wish to drop all elements in the list that begin with
> the ";" character.
>
> As a simplified example, suppose I have the following list S:
>
> S = {"abc", ";def", "ghi", ";jkl", "; mno", "pqr;X"}
>
> I wish to drop from S all elements that begin with ";". So, I want to
> obtain:
>
> {"abc", "ghi", "pqr;X"}
>
> Will you please help me know how to do this? Can this be done with
> DeleteCases? For example, I tried:
>
> DeleteCases[S, StringTake[#, 1] == ";"&]
>
> and
>
> DeleteCases[S, ";" ~~ __]
>
> but I am wrong: these do not work. Can you please help me?
>
> Thanks so much.
>
> Andrew DeYoung
> Carnegie Mellon University
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Question about DeleteCases to remove list elements based on first character Adriano Pascoletti <adriano.pascoletti@uniud.it> - 2012-01-17 10:58 +0000
csiph-web