LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default 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.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test for string of space chars? Robert Crandal[_2_] Excel Programming 4 December 30th 10 08:29 PM
Test for NULL string? Robert Crandal Excel Programming 3 January 16th 10 06:59 PM
extract cusotmer name from test string Dinesh Excel Worksheet Functions 5 June 23rd 09 01:27 AM
logical test and concatenate(string) dpayne Excel Discussion (Misc queries) 7 April 5th 07 08:30 PM
Test String LucB Excel Discussion (Misc queries) 2 November 29th 06 02:49 AM


All times are GMT +1. The time now is 09:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"