Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
String prod="pizza cafe",i want to print "PizzaCafe" .How to do that in Asp.net?i want to minimize space between pizza and cafe?
Posted

You need to replace the spaces inside the string. so you do that with string.replace:

C#
string originalString = "Pizza Cafe";
string minString = originalString.Replace(" ", "");

//minString now contains "PizzaCafe"


To add title casing, you can do this:

C#
string originalString = "pizza cafe";
string minTitleString = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(originalString).Replace(" ", "");

//minTitleString = "PizzaCafe"


Its long, but if you add a reference "using System.Globalization" at the top, it can be shortened to:

C#
string minTitleString = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(originalString).Replace(" ", "");
 
Share this answer
 
v3
Comments
Member 10523388 21-Jan-14 16:42pm    
its "pizza cafe" not "Pizza Cafe",how to do in that case???
Ron Beyer 21-Jan-14 16:46pm    
Doesn't matter what it is, just use your string and the replace function that I outlined above. If you actually show your code, I could help more but I can't see your computer.
Ron Beyer 21-Jan-14 20:40pm    
I added additional information for title casing the text.
Matt T Heffron 21-Jan-14 21:11pm    
+5
Ron Beyer 21-Jan-14 21:14pm    
Thanks Matt!
Trim only removes spaces from start or end try to use replace as suggested Ron
 
Share this answer
 
v2
You can use split function to split words at space and then convert to uppercase the first letter of each word and then merge them all again (possibly using a StringBuilder in a loop).

Code left as an exercise to the reader.
 
Share this answer
 
Comments
use trim function

("tom cat").tostring().trim;
 
Share this answer
 
Comments
Ron Beyer 21-Jan-14 16:37pm    
Trim only removes spaces from the start or end of the string, not the middle of it. See my Solution 2.
Member 10523388 21-Jan-14 16:39pm    
not working

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