Solved

How many spaces in a textbox?

Posted on 2006-11-10
8
200 Views
Last Modified: 2010-04-23
Is there any easy way to determine how many spaces are in a textbox?  Or, how many non-space characters are in a textbox?

At any given time, the text box will have 5 characters, such as "AB   ", or "012  ", and I ultimately need to determine how many non-space characters there are--preferably without a lot of complex code.  Any suggestions?  TIA
0
Comment
Question by:sasllc
  • 4
  • 3
8 Comments
 
LVL 13

Assisted Solution

by:newyuppie
newyuppie earned 100 total points
Comment Utility
try maybe:

        Dim i As Integer

        For Each c As Char In TextBox1.Text.ToCharArray
            If Char.IsSeparator(c) Then
                i += 1
            End If
        Next

        MessageBox.Show("Spaces: " & i)
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 300 total points
Comment Utility
Try nice quick:

Dim CharsSpaces as integer = TextBox1.text.Split(" ").GetUpperBound(0)
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 100 total points
Comment Utility
Hi sasllc;

Is this simple enough.

        Dim input As String = "AB   "     ' Test Data
        Dim strLen As Integer = 0         ' Number of chars in string

        strLen = input.Replace(" "c, String.Empty).Length

Fernando
0
 
LVL 13

Expert Comment

by:newyuppie
Comment Utility
simple not always means SINGLE LINED....
it should also be understandable and readable by a beginner.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
@newyuppie

And what is not understandable about replacing all spaces with an empty string and getting the length like the below line?

        input.Replace(" "c, String.Empty).Length

Fernando
0
 
LVL 13

Expert Comment

by:newyuppie
Comment Utility
hi fernando,
well what i meant is that it may be the case that beginner programmers dont know or dont wish to know how a particular piece of code works, as long as its doing the job. your code is very simple and clever, im not saying its not. but why assume that everybody would know that if you code " "c it means a char? in fact I didnt know until last week browsing the questions!
cheers
NY
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Hi NY;

I do not assume that what I post is understandable to everyone who reads it. I do hope that they at least try the code and for those parts that they do not understand to ask a follow up question to my post. I am always willing to explain my answers and to help others understand what I have done. If we do not try new things then how are we to grow in the profession we have selected. As you stated that you read other post and pick up new things that you did not know so I hope that someone else will read this post and pick up new things.

You have a great day;

Fernando
0
 
LVL 13

Expert Comment

by:newyuppie
Comment Utility
agreed!
NY
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now