Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Comments
[no name] 23-Sep-12 18:49pm    
Split your string on the /, remove all empty entries, then reassemble the string.
Sergey Alexandrovich Kryukov 24-Sep-12 0:20am    
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

See this sample code:
C#
string test1 = "test1/test2/ /test3";
test1 = test1.Replace(" ", ""); //remove white space
test1 = test1.Replace("//", "/"); //remove additional slashes
MessageBox.Show(test1);
 
Share this answer
 
Comments
_Amy 24-Sep-12 1:13am    
Deserves +5!
JF2015 24-Sep-12 1:14am    
Thanks!
replace all ' ' characters with nothing ('')
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Sep-12 0:21am    
This is not "nothing"; Nothing is a VB.NET expression for null.
--SA
Michael Haephrati 21-Sep-17 15:36pm    
I shouldn't have used the term "nothing" but I meant that literally.
This is pseodo code. Can be implemented in C++
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900