Click here to Skip to main content
12,692,778 members (33,659 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C#
How can i remove any number of whitespace from a string:
example 1st string test1/test2/ /test3
example 2nd string test1/test2/ /test3

the number of whitespace keeps changing so i want a solution that can handle this changing number of whitespace and just produces like this
string test1/test2/test3


thanks
Posted 23-Sep-12 13:40pm
Comments
Wes Aday 23-Sep-12 18:49pm
   
Split your string on the /, remove all empty entries, then reassemble the string.
   
No need to remove; there is on string.Split option to remove empty line.
Besides, this solution would be a bit bulky, because only one "replace all" needed, string.Replace.
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

See this sample code:
string test1 = "test1/test2/ /test3";
test1 = test1.Replace(" ", ""); //remove white space
test1 = test1.Replace("//", "/"); //remove additional slashes
MessageBox.Show(test1);
  Permalink  
Comments
_Amy 24-Sep-12 1:13am
   
Deserves +5!
JF2015 24-Sep-12 1:14am
   
Thanks!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

replace all ' ' characters with nothing ('')
  Permalink  
Comments
   
This is not "nothing"; Nothing is a VB.NET expression for null.
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

This is pseodo code. Can be implemented in C++
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100