[Resolved]what if the textBox is empty? - Truncating white spaces...
Not :mad: anymore.
Iam trying to truncate the leading and trailing white spaces in a text box.How do I do it.
I am trying this piece of code,
string myStr = textBox1.Text;
for (int i=0; i<myStr.Length; i++)
{
if (myStr[i]='(')
{
myStr[0]=myStr[i];
}
}
textBox1.Text=myStr;
In this piece of code,
My text starts with ( and ends with ), so Iam checking if the first character is a ( and trying to reset the index of the array to the current position.
But I get the following errors saying
->Cannot implicitly convert type 'char' to 'bool'
->Property or indexer 'string.this[int]' cannot be assigned to -- it is read only
please help
Re: Truncating white spaces from text in a textBox
Use Trim();
string myStr = textBox1.Text.Trim();
Good luck;
Re: Truncating white spaces from text in a textBox
Thanks a million!
Should have known it would be this simple with .NET.
What happens if textBox1.text is empty?
what would happen if the textBox1.text is empty?
Re: what if the textBox is empty? - Truncating white spaces...
Nothing...are you wanting to test to make sure it's not empty?
Re: what if the textBox is empty? - Truncating white spaces...
"Nothing...are you wanting to test to make sure it's not empty?"
I just want to know if I leave the Textbox empty and after
String Str=textBox1.text.Trim();
what would be the value of Str ?
Re: what if the textBox is empty? - Truncating white spaces...
It won't have a value, it'll be nothing. Same as if you didin't have the Trim().