MathGroup Archive 2002

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

Search the Archive

Re: LetterQ and DigitQ question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35997] Re: [mg35971] LetterQ and DigitQ question
  • From: Richard Palmer <mapsinc at bellatlantic.net>
  • Date: Sun, 11 Aug 2002 05:14:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 8/9/02 4:05 PM, "Charles H. Dresser" <dresserc at gouldacademy.org> wrote:

> Hello,
> I have a problem with DigitQ and letterQ I would like for a string to
> yeild True when run with DigitQ if the the string looks like this:
> {1,2} 
> and false if it looks like this:
> {hello, there!!!}
> Right now both strings return False because of "{ , }". So, if there
> were anyway to include the charecters "{", "}", and "," into the
> DigitQ "0-9" list temperarelly that would work, but I am sure there is
> a better way to do that.   Thank You,
> Charles
> 
Try this

Dresser[string_String]:=
Module[{x},x=StringReplace[string," "->""];
    If[Or[StringTake[x,1]!="(",StringTake[x,-1]!=")"],Return[False]];
    Apply[And,     
       NumberQ[#]&/@ToExpression["{"<>StringDrop[StringDrop[x,1],-1]<>"}"]]]

This function trims blanks.  It will do a bit more than you require --
return True for (#,#,#,...#).   However you can easily make the fix to limit
it to two.  Additionally, you can quickly modify the code to get the numbers
back.  The setup will also let you easily modify it to integers, positive
integers, Numerics, etc.

Regards, 

Richard  Palmer



  • Prev by Date: Math 3.0 running but 4.0 little problem.
  • Next by Date: RE: Corresponding function to given values...
  • Previous by thread: RE: LetterQ and DigitQ question
  • Next by thread: Re: LetterQ and DigitQ question