473,385 Members | 1,343 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.

way to remove empty spaces from string

Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks
--
Paul G
Software engineer.
Nov 21 '05 #1
6 22839

August 9, 2004

This custom method works for both leading, trailing, and intermingling
spaces...

Private Sub RemoveSpaces()
Dim str() As String
Dim s As String = TextBox1.Text ' get the string to split
str = s.Split(" ") ' split string into array
s = String.Join("", str) ' join it with no character
TextBox1.Text = s ' redisplay string

End Sub

I have already tried this method and it works great!

Joseph MCP
"Paul" wrote:
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks
--
Paul G
Software engineer.

Nov 21 '05 #2
temparray = array.Replace(" ", "") seemed to do the trick.

"Paul" wrote:
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks
--
Paul G
Software engineer.

Nov 21 '05 #3

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks
--
Paul G
Software engineer.


Dim myString As String = "This is my string with spaces."

myString = myString.Replace(" ", String.Empty)
Mythran
Nov 21 '05 #4
ok thanks for the information.

"Joseph MCP" wrote:

August 9, 2004

This custom method works for both leading, trailing, and intermingling
spaces...

Private Sub RemoveSpaces()
Dim str() As String
Dim s As String = TextBox1.Text ' get the string to split
str = s.Split(" ") ' split string into array
s = String.Join("", str) ' join it with no character
TextBox1.Text = s ' redisplay string

End Sub

I have already tried this method and it works great!

Joseph MCP
"Paul" wrote:
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks
--
Paul G
Software engineer.

Nov 21 '05 #5
* "=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> scripsit:
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks


Take a look at the string's 'Replace' method or 'Strings.Replace' and
replace the " " with a zero-length string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
ok thanks for the additional information.

"Herfried K. Wagner [MVP]" wrote:
* "=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> scripsit:
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks


Take a look at the string's 'Replace' method or 'Strings.Replace' and
replace the " " with a zero-length string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

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

Similar topics

3
by: Armin Irger | last post by:
Hi, i'am running a debian sarge with the delivered apache2 mysql and php4. The file "mitarbeiter_eingabe.php" gets the data over a html <FORM> and send it to...
9
by: ted | last post by:
I'm having trouble using the re module to remove empty lines in a file. Here's what I thought would work, but it doesn't: import re f = open("old_site/index.html") for line in f: line =...
17
by: AMC | last post by:
Hi, I'm using an include file to store the connection string to a database. Whenever I try to reference that string to open a connection in the page that includes the file I get the error 'empy...
4
by: nescio | last post by:
hello, i am building a function that checks whether a entered number is a valed number. this works fine, but there is a small problem: - when there is an empty space in the number or when...
6
by: Charlie | last post by:
Hi: Is there any difference between string.Empty and String.Empty? And what is the benefit of using it over "". Thanks, Charlie
5
by: LEM | last post by:
Hi, I'm trying to remove any empty lines from a string, and I am doing the following: String pp; pp = "\r\n\r\n1\r\n23\r\n\r\n4"; pp = pp.Replace("\r\n\r\n", "\r\n");
1
by: buggtb | last post by:
Hi Guys, I've been given the joyous task of updating some very old scripts at work and I could do with a little help. Our Unix system dumps text files to pseudo spoolers that our windows...
36
by: laredotornado | last post by:
Hi, I'm using PHP 5. I have an array of strings. What is the simplest way to remove the elements that are empty, i.e. where the expression "empty($elt)" returns true? Thanks, - Dave
2
by: SwapnilD | last post by:
I'm implementing a feature which reads comma separated txt file from server(one line at a time). Format of file is fixed, There are 3 columns on each row. After reading the row from file I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.