MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: question on Cases with elements that might be strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86557] Re: question on Cases with elements that might be strings
  • From: dh <dh at metrohm.ch>
  • Date: Thu, 13 Mar 2008 20:51:30 -0500 (EST)
  • References: <frasc3$1hm$1@smc.vnet.net>


Hi Ramiro,

StringExpression can only be used with string operators. Consider e.g.:

StringMatchQ[ "s1",  StringExpression["s",NumberString]]

MatchQ[ "s1",  StringExpression["s",NumberString]]

as a quick fix, you could try to convert your data to a string using 

ToString.

hope this helps, Daniel



ramiro wrote:

> Hi,

> 

> The following is a valid pattern match:

> 

> In[96]:= StringMatchQ["s1", StringExpression["s", NumberString]]

> 

> Out[96]= True

> 

> HOWEVER, the following does not work:

> In[89]:= Cases[{{1 -> "s1", 1}, {2 -> "s2", 2}}, {_ -> 

> StringExpression["s", NumberString], _}]

> 

> Out[89]= {}

> 

> Even though this works:

> In[95]:= Cases[{{1 -> "s1", 1}, {2 -> "s", 2}}, {_ -> 

> StringExpression["s"], _}]

> 

> Out[95]= {{2 -> "s", 2}}

> 

> 

> How come cases does not work on ln[89]?

> 

> Ramiro

> 




  • Prev by Date: NotebookClose
  • Next by Date: Re: Need help to find position of max location
  • Previous by thread: question on Cases with elements that might be strings
  • Next by thread: Re: question on Cases with elements that might be strings