I have a training program that is used by MANY different people. I have encountered many formatting issues already (like not allowing initials) but now I have a new one that I'm not sure about. When the code tests the name in the TextBox.Leave function, I can find if there is more than one space character in the box, and I can see if it is between the names, but if there is more than one, how do I remove ONLY one space?
bklynman01 2 Junior Poster in Training
Recommended Answers
Jump to PostTo remove ALL spaces:
myString = myString.Replace(" ", "")
To remove leading and trailing spaces:
myString = myString.Trim()
Note: this removes any white space, so newlines, tabs, etc. would be removed.
Jump to PostDim StringWithMultipleSpaces As String = " John Doe" Dim StringWithOneSpace As String = String.Join(" ", StringWithMultipleSpaces.Trim.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries))
Jump to PostTextBox1.Text = String.Join(" ", TextBox1.Text.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries))
If you had this "<4 spaces> John <10 spaces> Doe <1000 spaces>"
The TextBox1.Text.Split(New Char() {" "}c, StringSplitOptions.RemoveEmptyEntries part will return a string array containing 2 items John,Doe. The String.Join part puts them back together with 1 …
All 9 Replies
vishalrane 0 Junior Poster in Training
bklynman01 2 Junior Poster in Training
vishalrane 0 Junior Poster in Training
vishalrane 0 Junior Poster in Training

Unhnd_Exception
vishalrane 0 Junior Poster in Training
bklynman01 2 Junior Poster in Training

Unhnd_Exception
bklynman01 2 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.