Message-ID: <CA+hbrhXfBzOuqaGY=B9MA_nPM6zQF+xqPgK+9G33JAUsrYu20g@mail.gmail.com>
Date: 2011-08-03T00:13:19Z
From: Peter Langfelder
Subject: Is a string all blanks?
In-Reply-To: <4E385919020000CB000919C3@medicine.umaryland.edu>
On Tue, Aug 2, 2011 at 5:07 PM, John Sorkin <JSorkin at grecc.umaryland.edu> wrote:
> windows 7
> R 2.12.1
>
> Is there any easy way to determine if a sting contains nothing but blanks? I need to check a series of strings of various length.
>
> OneBlank <- " "
> TwoBlanks <- " ?"
> ThreeBlanks <- " ? "
> NoBlanks <- "NoBlanks"
>
> What I want would be a function such as ALLBLANKS that would return the following
> ALLBLANKS(OneBlank) would be true (or 1)
> ALLBLANKS(TwoBlanks) would be true (or 1)
> ALLBLANKS(ThreeBlanks) would be true (or 1)
> ALLBLANKS(NoBlanks) would be false (or 0)
ALLBLANKS = function(x) {x==paste(rep(" ", nchar(x)), collapse = "")}
> ALLBLANKS(" ")
[1] TRUE
> ALLBLANKS(" ")
[1] TRUE
> ALLBLANKS(" A ")
[1] FALSE
HTH,
Peter