473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

checking for spaces

How do I check for spaces in a string variable? Nothing but spaces or
nothing.
I am using
if trim(x) = "" then
which works but I was wondering if there was a cleaner way to do it.

I prefer not using variant variables.

Thank you
Smokey
Jul 17 '05 #1
7 8997
> How do I check for spaces in a string variable? Nothing
but spaces or nothing. I am using
if trim(x) = "" then
which works but I was wondering if there was a cleaner
way to do it.
I can't imagine anything that would be too much "cleaner" than that.
Here are two alternatives to using the Trim function (neither of which
are necessarily "cleaner")...

If Not X Like "*[! ]*" Then

or

If X = Space$(Len(X)) Then

I prefer not using variant variables.


If that is the case, then you should put a $ sign after the keyword
"Trim", like this...

If Trim$(X) = "" Then

With the $ sign, Trim returns a String value directly; without the $
sign, Trim returns a Variant with a sub-type of String.
Rick - MVP

Jul 17 '05 #2

"Smokey Joe" <ol*******@yahoo.com> skrev i en meddelelse
news:5j********************************@4ax.com...
How do I check for spaces in a string variable? Nothing but
spaces or
nothing.
I am using
if trim(x) = "" then


As clean as it gets.....

Or this......

IF EmptyString(X) THEN
Function EmptyString(str as string) as Boolean
EmptyString = (Trim(str) = "")
End Function

Build a library of support-functions that suits you....
--
/\ preben nielsen
\/\ pr**@post.tele.dk
Jul 17 '05 #3

"Smokey Joe" <ol*******@yahoo.com> wrote in message
news:5j********************************@4ax.com...
| How do I check for spaces in a string variable? Nothing but spaces or
| nothing.
| I am using
| if trim(x) = "" then
| which works but I was wondering if there was a cleaner way to do it.
|
| I prefer not using variant variables.
|
| Thank you
| Smokey

As already said, that's pretty clean.

I would use
If Len(Trim(X)) = 0 Then
just because - um, I guess because it makes more sense to me.
Jul 17 '05 #4
> | How do I check for spaces in a string variable? Nothing but spaces
or
| nothing.
| I am using
| if trim(x) = "" then
| which works but I was wondering if there was a cleaner way to do it.
|
| I prefer not using variant variables.
|
| Thank you
| Smokey

As already said, that's pretty clean.

I would use
If Len(Trim(X)) = 0 Then
just because - um, I guess because it makes more sense to me.


It is also faster than comparing String values directly (although I
would still throw the $ sign on the end of the Trim keyword in order to
force the Trim function to return a String value directly (otherwise,
without the $ sign, Trim returns a Variant with a sub-type of String).

Rick - MVP

Jul 17 '05 #5
Thank you to everyone.

There is a language where you can say if x = spaces etc.
To me that seems "clean".

Smokey
Jul 17 '05 #6
Rick

I am sitting hear searching all of the docs that came with vb6 and
msdn and cannot find anything that explains the difference between
trim and trim$ or any of the ...$ functions or statements.

Where would I find the explanation? Are there other differences
besides returning a string vs a variant(string)

Thank you
Smokey

Jul 17 '05 #7
Smokey Joe wrote:
Thank you to everyone.

There is a language where you can say if x = spaces etc.
To me that seems "clean".

Smokey


G'day Smokey,
seems silly but ...
If x = " " then ...

For i = 1 to len(myString)
x = mid(myString,i,1)
If x = " " then
myString = Replace(myString, " ", "")
end if
next i

untested but you'll figure it out, I hope.
in VB select a keyword i.e. Replace then press F1.
cheers
build
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul Fitzpatrick | last post by:
Hi, This is a real beginner question! I have a form with a few types of products. I need to limit the number that the user puts in for quantity of each product - I have to keep it below 2. ...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
3
by: Luke - eat.lemons | last post by:
Hi, Could someone tell me the correct quotation to get around spaces in paths for: Server.MapPath("\\server\share\spaces in name.mdb") I know its bad practice to use spaces but...
15
by: H. | last post by:
What's the easiest way to check if an argument entered at the command line is a number? I know that one way would be to treat the argument as a character string, and then manually check each...
14
Markus
by: Markus | last post by:
Making a basic validation script, i hit a snag. If user was to input say " "(minus quotes), into the textfield and then submit it the length check i have used would return it as true and...
3
by: bstjean | last post by:
Hi everyone, I am trying to find an efficient way to perform a special query. Let me explain what I want. Let's say we are looking for all description that match "this is the target". In...
21
by: ningxin | last post by:
Hi, i am currently taking a module in c++ in the university, and was given an assignment. because i have no prior background on the subject, everything is kind of new to me. i have tried for quite...
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.