Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all..


in my projects i have textbox in that text box iam pacing many string variable.. some time some string variable have values some time it will not have.. when its not have any value its showing some spaces.. so what shall i do for it.. pls guide me
Posted
Comments
Johnny J. 7-Oct-10 7:24am    
Could you provide a code sample, please, or rephrase your question? It is not understandable!

Is this what you meant?
C#
protected void Page_Load(object sender, EventArgs e)
{
   // this will remove any spaces after the contents of the text box have been submitted to the server.
   string nospaces = myTextBox.Text.Trim();

   ... do something with the trimmed string ...
}
 
Share this answer
 
v2
Trimming the text box value will remove the space at the beginning and at the end of the text

TextBox1.Text.Trim()
 
Share this answer
 
Comments
Nathan St 7-Oct-10 7:50am    
That code will run, but it won't do what you say because it doesn't do anything with the result from the Trim method.

TextBox1.Text = TextBox1.Text.Trim();

I think that's what you meant :)
Baji Jabbar 7-Oct-10 8:00am    
Why you are assigning the TextBox value back to the text box?. You can use this Trim with any string object.

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