473,664 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 22875

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**@discussio ns.microsoft.co m> wrote in message
news:C2******** *************** ***********@mic rosoft.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.Replac e(" ", 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**@discussio ns.microsoft.co m> 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.Replac e' 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**@discussio ns.microsoft.co m> 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.Replac e' 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
6602
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 "mysql_mitarbeiter_daten_hinzufuegen.php" to write it in an mysql database. These already worked on php3 and mysql-3 and now on php4 and mysql4 it doesn't work. I can't found any changes between php3 and php4, mysql3 and mysql4 that explained the fact that only empty spaces are...
9
23497
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 = re.sub(r'^\s+$|\n', '', line) print line
17
3236
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 connection string' . When I write the string to the page using response.write(connectionstring) it shows up fine. Is the something else that I need to do? Thanks
4
11611
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 there are dot's in the number the function does not work properly; - my question is this: how do i get rid of the empty spaces and/or dot's
6
13778
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
30968
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
2511
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 machines can then pick up and process. Now the guy who wrote one of the reports is obviously a bit clueless and the certain lines don't match up so for example our % line is a couple of spaces too far across. A09 62371 __7.20%
36
9158
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
2179
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 insert it in a database table. But first value of each row aoutomatically appends two blank spaces, even if there are no blank spaces at the begining of each row. I tried to use "TRIM/LTRIM/Replace" to remove blank spece from the first value of...
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8778
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.