Test if a string contains only whitespaces
Robert Crandal wrote:
"Auric__" wrote in message
.116...
Built in? Not that I know of, but you could try this:
Function isWhitespace(ByVal what As String) As Boolean
what = Replace(what, " ", "")
what = Replace(what, vbTab, "")
what = Replace(what, vbCr, "")
what = Replace(what, vbLf, "")
isWhitespace = CBool(Len(what))
End Function
Hi Auric..... I tried the above function but it seems to return TRUE
for cases that should be false. I ran it on the below data file:
item1 scissors
item2 glue
Each line is read into a string variable. I then passed each string
variable into "isWhitespace()" one at a time and it returned TRUE
each time. Am I doing something wrong here?
(This is what happens when I post while tired...)
No, Ron Rosenfeld is correct, I got the truth values reversed. The last line
should be:
isWhitespace = Not(CBool(Len(what)))
....or you can use one of the solutions Ron or RB Smissaert posted.
--
He doesn't know when to give up, this guy.
|