Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5024 > unrolled thread

String Deletion

Started byDon <donabc@comcast.net>
First post2011-09-17 10:30 +0000
Last post2011-09-19 11:13 +0000
Articles 6 — 5 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  String Deletion Don <donabc@comcast.net> - 2011-09-17 10:30 +0000
    Re: String Deletion "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-09-18 08:12 +0000
    Re: String Deletion David Bailey <dave@removedbailey.co.uk> - 2011-09-18 08:10 +0000
    Re: String Deletion "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-09-18 08:20 +0000
    Re: String Deletion Tyler <hayes.tyler@gmail.com> - 2011-09-18 08:25 +0000
      Re: String Deletion Tyler <hayes.tyler@gmail.com> - 2011-09-19 11:13 +0000

#5024 — String Deletion

FromDon <donabc@comcast.net>
Date2011-09-17 10:30 +0000
SubjectString Deletion
Message-ID<j51sst$pfv$1@smc.vnet.net>
Given a simple list of strings:

list =  List["Z:XBREG","Z:XBREH","Z:XBREI","Z:ZZ6P","Z:ZZ6Q","aye"]

how does one delete all the strings with a colon (:) anywhere in the string?

DeleteCases[list, ___:___]  looks very logical  and should work,
but of course it doesn't .

Also, there is a StringCases function which would seem
to correspond with the Cases function.  There is a
DeleteCases function but no string counterpart, namely,
DeleteString function.  Any reason for this?  

Thanks in advance.

[toc] | [next] | [standalone]


#5029

From"Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Date2011-09-18 08:12 +0000
Message-ID<j54966$682$1@smc.vnet.net>
In reply to#5024
On Sat, 17 Sep 2011 11:30:53 +0100, Don <donabc@comcast.net> wrote:

> Given a simple list of strings:
>
> list =  List["Z:XBREG","Z:XBREH","Z:XBREI","Z:ZZ6P","Z:ZZ6Q","aye"]
>
> how does one delete all the strings with a colon (:) anywhere in the  
> string?
>
> DeleteCases[list, ___:___]  looks very logical  and should work,
> but of course it doesn't .
>
> Also, there is a StringCases function which would seem
> to correspond with the Cases function.  There is a
> DeleteCases function but no string counterpart, namely,
> DeleteString function.  Any reason for this?
>
> Thanks in advance.
>

___:___ is not a particularly meaningful pattern. Its FullForm makes this  
clear:

Optional[BlankNullSequence[],BlankNullSequence[]]

To achieve what you want, you could try something like the following:

In[1] :=
list = {"Z:XBREG", "Z:XBREH", "Z:XBREI", "Z:ZZ6P", "Z:ZZ6Q", "aye"};

In[2] :=
Select[list, StringFreeQ[#, ":"] &]

Out[2] =
{"aye"}

[toc] | [prev] | [next] | [standalone]


#5041

FromDavid Bailey <dave@removedbailey.co.uk>
Date2011-09-18 08:10 +0000
Message-ID<j5492b$65e$1@smc.vnet.net>
In reply to#5024
On 17/09/2011 11:30, Don wrote:
> Given a simple list of strings:
>
> list =  List["Z:XBREG","Z:XBREH","Z:XBREI","Z:ZZ6P","Z:ZZ6Q","aye"]
>
> how does one delete all the strings with a colon (:) anywhere in the string?
>
> DeleteCases[list, ___:___]  looks very logical  and should work,
> but of course it doesn't .
>
> Also, there is a StringCases function which would seem
> to correspond with the Cases function.  There is a
> DeleteCases function but no string counterpart, namely,
> DeleteString function.  Any reason for this?
>
> Thanks in advance.
>
The short answer (one of several possible) is:

ll={"Z:XBREG","Z:XBREH","Z:XBREI","Z:ZZ6P","Z:ZZ6Q","aye"};
DeleteCases[ll,x_/;StringMatchQ[x,___~~":"~~___]]

{"aye"}

The longer answer is to encourage you to learn the syntax of 
Mathematica! If you had, you would realise that the colon in 
DeleteCases[list, ___:___] appears in the context of an operator - it is 
not a character in a string, so that expression is not going to pick out 
strings containing a colon, any more than it is going to pick out 
strings containing "_", or "[", or "]".

Any computer language that allows character/string manipulation, has to 
distinguish between characters representing themselves, and characters 
that are part of the expression syntax.

StringCases operates on a string (although the first argument can be a 
list of strings, but that only applies StringCases to every item of the 
list).

David Bailey
http://www.dbaileyconsultancy.co.uk

[toc] | [prev] | [next] | [standalone]


#5048

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2011-09-18 08:20 +0000
Message-ID<j549jj$6de$1@smc.vnet.net>
In reply to#5024
"Don" <donabc@comcast.net> schrieb im Newsbeitrag 
news:j51sst$pfv$1@smc.vnet.net...
> Given a simple list of strings:
>
> list =  List["Z:XBREG","Z:XBREH","Z:XBREI","Z:ZZ6P","Z:ZZ6Q","aye"]
>
> how does one delete all the strings with a colon (:) anywhere in the 
> string?
>
> DeleteCases[list, ___:___]  looks very logical  and should work,
> but of course it doesn't .
>
> Also, there is a StringCases function which would seem
> to correspond with the Cases function.  There is a
> DeleteCases function but no string counterpart, namely,
> DeleteString function.  Any reason for this?
>
> Thanks in advance.
>
What about the following two solutions?

list = List["Z:XBREG", "Z:XBREH", "Z:XBREI", "Z:ZZ6P", "Z:ZZ6Q", "aye"]
{Z:XBREG, Z:XBREH, Z:XBREI, Z:ZZ6P, Z:ZZ6Q, aye}

Complement[list, Select[list, StringPosition[#, ":"] != {} &]]
{aye}

Complement[list, Flatten[StringCases [#, _ ~~ ":" ~~ __] & /@ list]]
{aye}

Best regards,
Wolfgang 

[toc] | [prev] | [next] | [standalone]


#5054

FromTyler <hayes.tyler@gmail.com>
Date2011-09-18 08:25 +0000
Message-ID<j549t6$6gj$1@smc.vnet.net>
In reply to#5024
list = List["Z:XBREG", "Z:XBREH", "Z:XBREI", "Z:ZZ6P", "Z:ZZ6Q",
"aye"];
StringReplace[list, {":"} -> ""]

{"ZXBREG", "ZXBREH", "ZXBREI", "ZZZ6P", "ZZZ6Q", "aye"}

[toc] | [prev] | [next] | [standalone]


#5084

FromTyler <hayes.tyler@gmail.com>
Date2011-09-19 11:13 +0000
Message-ID<j5785c$jb9$1@smc.vnet.net>
In reply to#5054
On Sep 18, 4:25 am, Tyler <hayes.ty...@gmail.com> wrote:
> list = List["Z:XBREG", "Z:XBREH", "Z:XBREI", "Z:ZZ6P", "Z:ZZ6Q",
> "aye"];
> StringReplace[list, {":"} -> ""]
>
> {"ZXBREG", "ZXBREH", "ZXBREI", "ZZZ6P", "ZZZ6Q", "aye"}

Ooops! Looks like I should've read the post more. Sorry about that.

Cheers,

t.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web